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.
Zero/ZeroLevel/Services/Network/Utils/Networks/Network.cs

47 lines
1.5 KiB

5 years ago
using System;
using System.IO;
using System.Net;
2 years ago
using System.Net.Http;
5 years ago
namespace ZeroLevel.Services.Network.Utils
{
2 years ago
/// <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
{
using (var clientHandler = new HttpClientHandler())
{
clientHandler.ServerCertificateCustomValidationCallback = (_, _, _, _) => true;
clientHandler.UseCookies = true;
clientHandler.CookieContainer = new CookieContainer();
using (var client = new HttpClient(clientHandler))
{
var message = new HttpRequestMessage(HttpMethod.Get, "http://ipv4.icanhazip.com");
using (var response = client.SendAsync(message).Result)
2 years ago
{
return response.Content.ReadAsStringAsync().Result;
}
}
}
}
catch (Exception e)
{
Console.WriteLine("Error: " + e.Message);
return "";
}
}
}
}
5 years ago
}

Powered by TurnKey Linux.