Ermittele die öffentliche IPv4 Adresse des PC's über den Dienst von http://checkip.dyndns.org.
Stand : September 2014
private string GetPublicIPv4()
{
try
{
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 a4 = a3[0];
return a4;
}
catch (Exception)
{
return null;
}
}
1 Kommentare zum Snippet