Getting the local IP address

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!
 
E

Ed Kaim [MSFT]

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.
 
J

Jonathan

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top