Asp獲取真實IP地址,最簡單可用一句話獲?。?/p>
ip=request.ServerVariables("REMOTE_ADDR")
response.Write(ip)
但這種方法對代理服務器上網(wǎng)的就不準了,故比較全面的是用下面的方法:取得用戶真實IP,對代理地址仍然有效;返回值:文本類型的IP地址
%
'******************************
'函數(shù):GetUserTrueIP()
'參數(shù):無
'作者:阿里西西
'日期:2007/7/13
'描述:取得用戶真實IP,對代理地址仍然有效;返回值:文本類型的IP地址
'示例:%=GetUserTrueIP()%>
'******************************
Function GetUserTrueIP()
dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
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
GetUserTrueIP = Trim(Mid(strIPAddr, 1, 30))
End Function
%>
其他網(wǎng)友的補充
%
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
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)
%>
得到真實IP
Function GetReallyIP()
Dim strIP
strIP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If strIP="" Or InStr(strIP,"unknown") Then
strIP=Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(strIP,",") Then
strIP=Split(strIP,",")(0)
ElseIf InStr(strIP,";") Then
strIP=Split(strIP,";")(0)
End If
GetReallyIP=Trim(strIP)
End Function
以上就是asp 取得用戶真實IP,對代理地址仍然有效的函數(shù)的詳細內(nèi)容,更多關(guān)于asp真實IP的資料請關(guān)注腳本之家其它相關(guān)文章!
您可能感興趣的文章:- 做了CDN獲取用戶真實IP的函數(shù)代碼(PHP與Asp設(shè)置方式)
- 做了CDN加速的ASP網(wǎng)站獲取用戶真實IP程序
- ASP如何獲取真實IP地址