22 lines
533 B
C#
22 lines
533 B
C#
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
public static class Global
|
|
{
|
|
|
|
public static readonly string localhost = "127.0.0.1";
|
|
|
|
public static string GetLocalIPAddress()
|
|
{
|
|
var host = Dns.GetHostEntry(Dns.GetHostName());
|
|
foreach (var ip in host.AddressList)
|
|
{
|
|
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
return ip.ToString();
|
|
}
|
|
}
|
|
throw new Exception("No network adapters with an IPv4 address in the system!");
|
|
}
|
|
}
|