IPAddress of a login system

前端 未结 6 2517
花落未央
花落未央 2020-12-22 05:42

Using the bellow code .

protected string GetUserIP()
{
    string strUserIP = string.Empty;
    if (HttpContext.Current.Request.ServerVariables[\"HTTP_X_FORW         


        
6条回答
  •  自闭症患者
    2020-12-22 06:03

    To get the IpAddress use the below code

    string IPAddress = GetIPAddress();
        public string GetIPAddress()
        {
    
            IPHostEntry Host = default(IPHostEntry);
            string Hostname = null;
            Hostname = System.Environment.MachineName;
            Host = Dns.GetHostEntry(Hostname);
            foreach (IPAddress IP in Host.AddressList) {
                if (IP.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
                    IPAddress = Convert.ToString(IP);
                }
            }
            return IPAddress;
    
        }
    

    Source

提交回复
热议问题