Get User's IP Address

后端 未结 5 1691
半阙折子戏
半阙折子戏 2020-12-05 10:39

How can I get the current visitors IP address?

5条回答
  •  萌比男神i
    2020-12-05 11:21

    Try this to get external ip address of user..

    public static string getExternalIp()
        {
            try
            {
    
                string externalIP;
                externalIP = (new WebClient()).DownloadString("http://checkip.dyndns.org/");
                externalIP = (new Regex(@"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"))
                             .Matches(externalIP)[0].ToString();
                return externalIP;
            }
            catch { return null; }
        }
    

提交回复
热议问题