Oleg
Oleg

Reputation: 1755

How can I determine Internal IP

I have a web service on IIS and I have two network interface cards. In my service I have code:

string host = System.Net.Dns.GetHostName();

    IPAddress ip = Dns.GetHostEntry(host).AddressList[2];

It gives me external ip adress, how I can find internal ip?

Upvotes: 3

Views: 615

Answers (1)

Rune Grimstad
Rune Grimstad

Reputation: 36300

You should get the local ip address(es) by calling Dns.GetHosEntry(""). That is, passing an empty string as the host name.

Alternatively you can use the System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces() method and go from there.

Upvotes: 2

Related Questions