欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
        }

上一篇:

下一篇: