I want to get the IP of my PC (the local IP taken from the router).
I could get the IP but with other IPs on the network. Is there a method to extract only the needed IP without getting all the IPs in an array and then choosing from them the needed one?
Code tried:
string strHostName = string.Empty;
strHostName = Dns.GetHostName();
IPHostEntry ipHostEntry = Dns.GetHostEntry(strHostName);
IPAddress[] address = ipHostEntry.AddressList;
foreach (var item in address)
{
Console.WriteLine(item.ToString());
}
The result of this code is a bunch of IPs found on the network including my IP (broadcast domain, IPv6 and similar stuff but not other devices' IPs). I want to get only my actual IP without getting all as the code will be published on a machine which I cannot monitor the IP all the time.