0

我正在使用下面的代码来了解客户端 ip,但它给了我的服务器 ip,如果有的话,请有人进行必要的更改,

提前致谢,

protected string GetComputer_InternetIP()
{
    // check IP using DynDNS's service
    WebRequest request = WebRequest.Create("http://checkip.dyndns.org");
    WebResponse response = request.GetResponse();
    StreamReader stream = new StreamReader(response.GetResponseStream());

    // IMPORTANT: set Proxy to null, to drastically INCREASE the speed of request
    //request.Proxy = null;

    // read complete response
    string ipAddress = stream.ReadToEnd();

    // replace everything and keep only IP
    return ipAddress.
        Replace("<html><head><title>Current IP Check</title></head><body>Current IP Address: ", string.Empty).
        Replace("</body></html>", string.Empty);
}
4

0 回答 0