Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Windows function call that get local hostname and IP address

Is there built-in windows C++ function call that can get hostname and IP address? Thanks.

like image 270
Stan Avatar asked May 29 '10 04:05

Stan


People also ask

How do you display the IP address and hostname of a local machine?

The IP address and hostname of any local computer can be determined using the java. net. InetAddress class.

What is Gethostbyname function?

The gethostbyname function returns a pointer to a hostent structure—a structure allocated by Windows Sockets. The hostent structure contains the results of a successful search for the host specified in the name parameter.

How do I find my local IP hostname?

Click the Windows Start button, then "All Programs" and "Accessories." Right-click on "Command Prompt" and choose "Run as Administrator." Type "nslookup %ipaddress%" in the black box that appears on the screen, substituting %ipaddress% with the IP address for which you want to find the hostname.


1 Answers

To get the hostname you can use: gethostname or the async method WSAAsyncGetHostByName

To get the address info, you can use: getaddrinfo or the unicode version GetAddrInfoW

You can get more information about the computer name like the domain by using the Win32 API: GetComputerNameEx.

like image 88
Brian R. Bondy Avatar answered Oct 04 '22 22:10

Brian R. Bondy