0

I've managed to get my static IP Address and some other mac addresses.

Using this code :

IPAddress[] addr = Dns.GetHostEntry( Dns.GetHostName() ).AddressList;
string dynamicip = addr[addr.Length - 3].ToString(); 

Any idea how to get the dynamic public address like the one on the site whatismyip.com?

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
user779444
  • 1,365
  • 4
  • 21
  • 38
  • Take a look at this [Post](http://stackoverflow.com/questions/66363/get-external-ip-address-over-remoting-in-c) – Mark Kram Jun 09 '11 at 00:26
  • You cannot do it without a 3rd party -- you need some site outside your network that can respond with the IP it saw your traffic from. – Joe Jun 09 '11 at 00:29

3 Answers3

5

whatismyip.com has an api (sort of) setup for this purpose here. you can use

public static IPAddress GetExternalIP()
{
        string url = "http://www.whatismyip.com/automation/n09230945.asp";
        WebClient webClient = new WebClient();
        string response = utf8.GetString(webClient .DownloadData(whatIsMyIp));
        IPAddress ip = IPAddress.Parse(response);
        return ip;   
}
Bala R
  • 107,317
  • 23
  • 199
  • 210
0

for IP Address you can use HttpContext.Current.Request.UserHostAddress;

for windows form check How to detect static ip using win app in c#

brgds

Community
  • 1
  • 1
s_h
  • 1,476
  • 2
  • 27
  • 61
  • nop, this is not the solution for windows form. that is for asp. I added a stack post explaining for winforms – s_h Jun 09 '11 at 00:29
  • @ sebastian_h, suppose if I want a product registration by detecting the ipaddress of the windows application's computer, how can I achieve if the computer is behind a router with static ip address ? – Coder323 Jun 09 '11 at 01:43
0

I think this is probably the question that you're asking: How to get the IP address of the server on which my C# application is running on?

Community
  • 1
  • 1
elRobbo
  • 613
  • 7
  • 10