Getting the local IP address

  • Thread starter Thread starter Jonathan
  • Start date Start date
J

Jonathan

Hi,

How can I get the IP address of the local machine using C#?

I tried Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
It always gives 192.168.2.2 which is not I want...

I also tried Dns.Resolve("localhost").AddressList[0];
It only gives the loop back address 127.0.0.1 ...also not I want...

Assume the local machine uses DHCP and don't have DNS name...how can I
get back its current IP address on the Internet?

Thanks!
 
That probably is your IP address, which was assigned through DHCP. If you
want to know what public sites will see your address as, you'll have to look
up the proxy instead.
 
Hi!~

Sorry, then how to look up the proxy? What is the class and program
statements used? Thanks!~

Ed Kaim said:
That probably is your IP address, which was assigned through DHCP. If you
want to know what public sites will see your address as, you'll have to look
up the proxy instead.

Jonathan said:
Hi,

How can I get the IP address of the local machine using C#?

I tried Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
It always gives 192.168.2.2 which is not I want...

I also tried Dns.Resolve("localhost").AddressList[0];
It only gives the loop back address 127.0.0.1 ...also not I want...

Assume the local machine uses DHCP and don't have DNS name...how can I
get back its current IP address on the Internet?

Thanks!
 
Back
Top