I believe this question may be quickly flagged as a duplicate. However, I do believe this is a legitimate question.
At this time, I'm getting my current IP address using the following code:
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress currentIpAddress = hostEntry.AddressList.FirstOrDefault(address => address.AddressFamily == AddressFamily.InterNetwork);
Console.WriteLine(currentIpAddress.ToString());
When I run this code, I get the first Ethernet adapter value I see when I run ipconfig
from a command-line. However, this value is different than the IP address I see when I run a query for "what is my ip address" on Google. I don't understand why these values are different. For that reason, I'm concerned that my code is incorrect.
How do I know if my code is correctly getting the IP address of the machine the app is currently running on?