Detailed ASP get user real IP code

Source: Internet
Author: User

Normally this will be able to obtain the IP address of the client, but if the client is using a proxy server to access, that is the proxy server IP address, rather than the real client IP address, to get through the proxy server to obtain the real IP address of the client, Use Microsoft's Request.ServerVariables ("Http_x_forwarded_for") that is not published in the general ASP tutorials Technical documentation, but note that if the client is not accessed through a proxy server, the The value that Request.ServerVariables ("Http_x_forwarded_for") takes will be empty. Therefore, if you want to use this method in your program, you can handle this:



<title> Welcome to visit this website </title>

<body>

<% ip_address=request.servervariables ("Http_x_forwarded_for")
If ip_address= "" Then
ip_address= Request.ServerVariables ("REMOTE_ADDR")

</body>

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

Let's look at a real example

Function get_cli_ip () ' takes real IP function, http_client_ip and then Http_x_forwarded_for remote_addr
Dim client_ip br> if Checkip (Request.ServerVariables ("Http_client_ip")) =true then
Get_cli_ip = Checkip (request.servervariables ("Http_client_ip"))
Else
MyArray = Split (Request.ServerVariables ("Http_x_forwarded_for"), ",")
If UBound (myarray) >=0 Then br> client_ip = Trim (myarray (0))
if Checkip (client_ip) =true then
Get_cli_ip = client_ip
Exit Function
End If
End If
Get_cli_ip = Request.ServerVariables ("remote_addr")
End If
End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.