Get the public ip of the user from through code

Kmandapalli
Posted by Kmandapalli under ASP.NET category on | Points: 40 | Views : 487
string url = "http://checkip.dyndns.org";
System.Net.WebRequest req = System.Net.WebRequest.Create(url);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
string response = sr.ReadToEnd().Trim();
string[] a = response.Split(':');
string a2 = a[1].Substring(1);
string[] a3 = a2.Split('<');
string strIpAddress = a3[0];
return strIpAddress;

Comments or Responses

Login to post response