mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
727 B
38 lines
727 B
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
|
|
namespace ZeroLevel.Services.Network.Utils
|
|
{
|
|
/// <summary>
|
|
/// Methods related to Network.
|
|
/// </summary>
|
|
public static class Network
|
|
{
|
|
/// <summary>
|
|
/// Gets the external IP Address.
|
|
/// </summary>
|
|
/// <value>The external IP Address.</value>
|
|
public static string ExternalIP
|
|
{
|
|
get
|
|
{
|
|
try
|
|
{
|
|
WebRequest request = WebRequest.Create("http://ipv4.icanhazip.com");
|
|
using (var response = request.GetResponse())
|
|
using (var sr = new StreamReader(response.GetResponseStream()))
|
|
{
|
|
return sr.ReadLine();
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Console.WriteLine("Error: " + e.Message);
|
|
return "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|