最简单的用以下语句:
ip=request.ServerVariables("REMOTE_ADDR")
response.Write(ip)
但这种方法对代理服务器上网的就不准了,故比较全面的是用下面的方法:
<%
Private Function getIP() //定义一个获取ip的函数
Dim strIPAddr //定义ip地址变量
//检测是否利用了代理:HTTP_X_FORWARDED_FOR,如果没有直接用Request.ServerVariables("REMOTE_ADDR") 获取
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") >0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
//如果使用了代理HTTP_X_FORWARDED_FOR,就从代理串中截取
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") >0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "") >0 Then
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")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
ip=getIP()
response.write(ip)
%>
欢迎分享,转载请注明来源:夏雨云
评论列表(0条)