I need a program to determine its LAN IP, the one other LAN clients would use to identify it. The .Net code I have found returns all IP addresses, including loopback and VMWare interfaces, so I get a list of Class C IPs.
I have already read through:
Find correct Ip address returned by Dns.GetHostEntry
Getting server ip using Dns.GetHostEntry in c#
Get IP address from hostname in LAN
Dns.GetHostEntry returns multiple IP addresses
Example code that returns all adapters, including the "right one", along with VMWare adapters, etc.
public string GetLanIP()
{
IPHostEntry host;
string localIP = "?";
host = Dns.GetHostEntry(Dns.GetHostName());
foreach (IPAddress ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
localIP = ip.ToString();
}
}
return localIP;
}
I have also tried creating a UDP client to the internet server in hopes I could find which LAN adapter was associated with it, so I could then find that adapter's IP Address, but no luck.
Can anyone advise on how to find the correct LAN IP that other computers on the same LAN would use to connect to it?