fix: 服务端使用本地IP

This commit is contained in:
2025-07-21 19:19:29 +08:00
parent e7c8d3fb9e
commit 5da9d9f4e2
6 changed files with 50 additions and 23 deletions

View File

@@ -0,0 +1,20 @@
using System.Net;
using System.Net.Sockets;
public static class Global {
public static readonly string localhost = "172.31.2.228";
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!");
}
}