Hallo an alle,
diese Methode gibt die eigene, öffentliche IP-Adresse zurück.
Usings:
using System.IO;
using System.Net;
Credits:
Koopakiller danke für die Tipps.
/// <summary>
/// Öffentliche IP auslesen
/// </summary>
/// <returns>IP-Adresse</returns>
IPAddress GetMyIP()
{
string Ip, Url = "http://bot.whatismyipaddress.com/";
HttpWebRequest Req = (HttpWebRequest)WebRequest.Create(Url);
using (HttpWebResponse Res = (HttpWebResponse)Req.GetResponse())
{
using (StreamReader Str = new StreamReader(Res.GetResponseStream()))
{
Ip = Str.ReadToEnd();
}
}
return IPAddress.Parse(Ip);
}
8 Kommentare zum Snippet