Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. How to get remote hostname from IP addr

How to get remote hostname from IP addr

Scheduled Pinned Locked Moved System Admin
questiondatabasesysadminwindows-adminjson
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andrew Allen
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • A Andrew Allen

      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

      D Offline
      D Offline
      Dudi Avramov
      wrote on last edited by
      #2

      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;
      

      }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups