Is there any code or method to get the IP addresses of the local system?
If you are in C#, you could use .NET:
using System;
using System.Net;
public static string GetLocalIP() {
var hosts = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ipEntry in host.AddressList)
{
if (ipEntry.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
}
You can later add a throw new Exception
at the end, it will show up if you have no IPv4 adapters installed.
To enumerate local IP addresses, use the Win32 API GetAdaptersInfo() (supports IPv4 only) or GetAdaptersAddresses() (supports IPv4 and IPv6) function. C/C++ examples are included in their documentation.