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:
 var html = new WebClient().DownloadString("http://checkip.dyndns.com/");  
 var ipStart = html.IndexOf(": ", StringComparison.OrdinalIgnoreCase) + 2;  
 IPAddress addr = IPAddress.Parse(html.Substring(ipStart, html.IndexOf("</", ipStart, StringComparison.OrdinalIgnoreCase) - ipStart));  
 string result = Convert.ToString(addr);  
 Console.WriteLine(result);  

No comments:

Post a Comment