How does ASP get real IP addresses?

zhaozj2021-02-16  198

Using Request.SerVariables ("Remote_ADDR") in ASP to get the client's IP address, but if the client is accessible to use the proxy server, the take is the IP address of the proxy server, not the real client IP address. To obtain a real IP address of the client through the proxy server, use the request.servervariables ("http_x_forwarded_for") to read.

But what you have to pay attention is not every proxy server, you can read the client with Request.ServerVariables ("http_x_forwarded_for")

The real IP, some use this method is still an IP of the proxy server.

One thing to note is that if the client does not pass the proxy server to access, the value taken by Request.ServerVariables ("http_x_forwarded_for") will be empty. Therefore, if this method is to be used in the program, it can be processed:

......

Userip = request.serverVariables ("http_x_forwarded_for")

IF userip = "" "" Userip = Request.serverVariables ("remote_addr")

......

That is: If the client passes the proxy server, take the value of http_x_forwarded_for, if not through the proxy server, take the value of Remote_ADDR.

转载请注明原文地址:https://www.9cbs.com/read-8351.html

New Post(0)