The simplest sentence is to use the following:
ip=request.ServerVariables("REMOTE_ADDR")
response.Write(ip)
However, this method is not accurate for proxy servers to access the Internet, so the more comprehensive method is to use the following method:
The code copy is as follows:
<%PrivateFunctiongetIP()
DimstrIPAddr
IfRequest.ServerVariables("HTTP_X_FORWARDED_FOR")=""ORInStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),"unknown")>0Then
strIPAddr=Request.ServerVariables("REMOTE_ADDR")
ElseIfInStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",",")>0Then
strIPAddr=Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1,InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",")-1)
ElseIfInStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),";")>0Then
strIPAddr=Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),1,InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),";")-1)
Else
strIPAddr=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
EndIf
getIP=Trim(Mid(strIPAddr,1,30))
EndFunction
ip=getIP()
response.write(ip)
%>