How to get remote hostname from IP addr
-
Any ideas on how to retrieve the hostname of a Windows server or workstation on the local workgroup or domain FROM the ip address only? What is the SDK/API function for this? I want to use InitiateSystemShutdown() and other SDK functions which take the hostname in the format "\\name", but I only have the IP address to start with. BOOL InitiateSystemShutdown( LPTSTR lpMachineName, // computer name LPTSTR lpMessage, // message to display DWORD dwTimeout, // length of time to display BOOL bForceAppsClosed, // force closed option BOOL bRebootAfterShutdown // reboot option ); The IP address is static and is on the LAN, so firewalls/proxies/NAT/etc. are not an issue. My local computer will not have any hostnames configured in its hosts/LMHOSTS, and will (probably) have to browse or query the remote computer. thanks in advance! (sorry if my terminology is not completely Microsoft-esque) Andrew
-
Any ideas on how to retrieve the hostname of a Windows server or workstation on the local workgroup or domain FROM the ip address only? What is the SDK/API function for this? I want to use InitiateSystemShutdown() and other SDK functions which take the hostname in the format "\\name", but I only have the IP address to start with. BOOL InitiateSystemShutdown( LPTSTR lpMachineName, // computer name LPTSTR lpMessage, // message to display DWORD dwTimeout, // length of time to display BOOL bForceAppsClosed, // force closed option BOOL bRebootAfterShutdown // reboot option ); The IP address is static and is on the LAN, so firewalls/proxies/NAT/etc. are not an issue. My local computer will not have any hostnames configured in its hosts/LMHOSTS, and will (probably) have to browse or query the remote computer. thanks in advance! (sorry if my terminology is not completely Microsoft-esque) Andrew
Use inet_addr and gethostbyaddr. Example:
int main(int argc, char* argv[])
{
WSADATA d;
WSAStartup(MAKEWORD(2,2), &d);
char szIP[] = "1.2.3.4";long ip = inet\_addr(szIP); HOSTENT \*pHostent = gethostbyaddr((char\*)&ip,4,AF\_INET); if (pHostent) { printf("%s is %s", szIP, pHostent->h\_name); } return 0;
}