c#,asp.net,asp.net MVC,asp.net Core 获取客户端IP
程序员文章站
2023-12-28 11:52:28
...
c#,asp.net,asp.net MVC,asp.net Core 获取客户端IP
获取客户端IP地址
using System.Text.RegularExpressions;
using System.Net;
public string GetIP()
{
string AddressIP = string.Empty;
foreach (IPAddress _IPAddress in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
{
if (_IPAddress.AddressFamily.ToString() == "InterNetwork")
{
AddressIP = _IPAddress.ToString();
}
}
return AddressIP;
}