C codymanix Dec 22, 2003 #1 how can I get the IP address of a computer when I only know its computername in a windows network?
D David Lowndes Dec 22, 2003 #2 how can I get the IP address of a computer when I only know its computername in a windows network? Click to expand... Here's an example doctored from Knowledge Base article 183988 "HOWTO: Retrieve the IP Address of the Remote PPP Peer": DWORD GetIpAddress(char *hostname) { DWORD dwIP = 0; TCHAR msg[128]; HOSTENT *lpHost=NULL; struct sockaddr_in dest; lpHost = gethostbyname(hostname); if (lpHost == NULL) { wsprintf(msg, _T("gethostbyname failed: %d"), WSAGetLastError()); MessageBox(NULL, msg, NULL, MB_OK); } else { for(int i=0; lpHost->h_addr_list != NULL ;i++) { memcpy(&(dest.sin_addr), lpHost->h_addr_list, lpHost->h_length); dwIP = ntohl( dest.sin_addr.S_un.S_addr ); } } return dwIP; } Dave
how can I get the IP address of a computer when I only know its computername in a windows network? Click to expand... Here's an example doctored from Knowledge Base article 183988 "HOWTO: Retrieve the IP Address of the Remote PPP Peer": DWORD GetIpAddress(char *hostname) { DWORD dwIP = 0; TCHAR msg[128]; HOSTENT *lpHost=NULL; struct sockaddr_in dest; lpHost = gethostbyname(hostname); if (lpHost == NULL) { wsprintf(msg, _T("gethostbyname failed: %d"), WSAGetLastError()); MessageBox(NULL, msg, NULL, MB_OK); } else { for(int i=0; lpHost->h_addr_list != NULL ;i++) { memcpy(&(dest.sin_addr), lpHost->h_addr_list, lpHost->h_length); dwIP = ntohl( dest.sin_addr.S_un.S_addr ); } } return dwIP; } Dave