Tuesday, May 7, 2013

Find the Static IP of a system using CSharp (C#)


Use the below code to get the Static IP address of your local system.
C# Code:
  1. var html = new WebClient().DownloadString("http://checkip.dyndns.com/");
  2. var ipStart = html.IndexOf(": ", StringComparison.OrdinalIgnoreCase) + 2;
  3. IPAddress addr = IPAddress.Parse(html.Substring(ipStart, html.IndexOf("</", ipStart, StringComparison.OrdinalIgnoreCase) - ipStart));
  4. string result = Convert.ToString(addr);
  5. Console.WriteLine(result);

No comments:

Post a Comment