I wrote the code for asp to get the real IP, and used the environment to test the situation of no agent, one-level or multi-level agents, and the copied code can be obtained normally. The code is as follows:
function checkip(checkstring)' Use regular expressions to determine whether the IP is legal
dim re1
set re1=new RegExp
re1.pattern=^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$
re1.global=false
re1.Ignorecase=false
checkip=re1.test(checkstring)
set re1=nothing
end function
Copy the code code as follows:
function get_cli_ip()'Get the real IP function, first HTTP_CLIENT_IP then HTTP_X_FORWARDED_FOR then REMOTE_ADDR
dim client_ip
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
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