tags:

views:

48

answers:

2

For example to get local ip address I use:

 string myHost = System.Net.Dns.GetHostName();
 string myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[0].ToString();
+2  A: 

here's a link that may help. http://www.dreamincode.net/forums/topic/24692-showing-the-external-ip-address-in-c%23/

There's a good post on doing a webrequest to WhatIsMyIP.com

derek
+1 - a web request is the ONLY way to do it. You need to get into the internet to know whether you are behind 1 or more NAT devices. SO, a web based API call to some external server returning your IP is it.
TomTom
A: 

You could try the following:

IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName());

The following is a use example:

lblStatus.Text = "My IP address is " +
IPHost.AddressList[0].ToString();

Edit: ha, ha, derek, beat me to it! ;P

Delan Azabani
Sadly, this may not give you the external ip, simply because the ip you get is still the one assigned to you by your local DNS - which may be on your little NAT router.
TomTom