>how can I get the IP address of a computer when I only know its computername
in a windows network?
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[i] != NULL ;i++)
{
memcpy(&(dest.sin_addr),
lpHost->h_addr_list[i],
lpHost->h_length);
dwIP = ntohl( dest.sin_addr.S_un.S_addr );
}
}
return dwIP;
}
Dave
--
MVP VC++ FAQ:
http://www.mvps.org/vcfaq