public string GetPublicIpAddressFromDnsOMatic()
{
string uri = "http://myip.dnsomatic.com/";
string responseBody = string.Empty;
try
{
WebRequest request = WebRequest.Create(uri);
using (WebResponse response = request.GetResponse())
{
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
responseBody = stream.ReadToEnd();
}
}
}
catch (Exception)
{
//TODO: Log Exception
}
var options = RegexOptions.IgnoreCase | RegexOptions.Compiled;
var regex = new Regex(@"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}", options);
var match = regex.Match(responseBody);
if (match.Success)
{
return match.Value;
}
return null;
}