Tuesday, April 9, 2013

A Dangerous Method

In contrast to what I thought was my last find-yourself-Sabrina posting, I've read online that the best way to go fish for the external IP is by way of a call to another service like so:

private string location()
{
   var request = (HttpWebRequest)WebRequest.Create("http://ifconfig.me");
   request.UserAgent = "curl";
   string publicIPAddress;
   request.Method = "GET";
   using (WebResponse response = request.GetResponse())
   {
      using (var reader = new StreamReader(response.GetResponseStream()))
      {
         publicIPAddress = reader.ReadToEnd();
      }
   }
   return publicIPAddress.Replace("\n", "");
}

No comments:

Post a Comment