asp 取得用户真实IP,对代理地址仍然有效的函数

编程学习 2021-07-05 10:58www.dzhlxh.cn编程入门
这篇文章主要介绍了asp 取得用户真实IP,对代理地址仍然有效的函数,需要的朋友可以参考下

Asp获取真实IP地址,最简单可用一句话获取:

ip=request.ServerVariables("REMOTE_ADDR")
response.Write(ip)

但这种方法对代理服务器上网的就不准了,故比较全面的是用狼蚁网站SEO优化的方法:取得用户真实IP,对代理地址仍然有效;返回值:文本类型的IP地址

<% 
'****************************** 
'函数:GetUserTrueIP() 
'参数:无 
'作者:阿里西西 
'日期: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 
%>

其他网友的补充

<%
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,对代理地址仍然有效的函数的详细内容,更多关于asp真实IP的资料请关注狼蚁SEO其它相关文章!

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板