Skip to content

Instantly share code, notes, and snippets.

@messboy
Last active February 16, 2016 02:14
html
public class NetWorkHelper
{
public static string GetPublicIP()
{
String direction = "";
WebRequest request = WebRequest.Create("http://checkip.dyndns.org/");
using (WebResponse response = request.GetResponse())
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
direction = stream.ReadToEnd();
}
//Search for the ip in the html
int first = direction.IndexOf("Address: ") + 9;
int last = direction.LastIndexOf("</body>");
direction = direction.Substring(first, last - first);
return direction;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment