Search code examples
c++winapiip-addresshostname

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.


Solution

  • 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.