|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
有个问题想请教你一下,呵呵:)你觉得将来学什么方向比较好,我真是想不出来,知道的太少了,麻烦了。aspxvb.net猎取实在IP的函数以下:
复制代码代码以下:
<scriptrunat="server">
PublicFunctionCheckIp(ByValipAsString)AsBoolean
DimpatAsString="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
DimregAsRegex=NewRegex(pat)
ifip=""Then
CheckIp=False
exitFunction
endif
CheckIp=reg.IsMatch(ip)
EndFunction
PublicFunctionget_cli_ip()AsString
If(Not(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP")IsNothing)AndCheckIp(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP"))=True)Then
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP")
ExitFunction
ElseIfNot(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")IsNothing)Then
Dimips()AsString=Split(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",")
ForiAsInteger=0Toips.Length-1
IfCheckIp(Trim(ips(i)))=TrueThen
get_cli_ip=Trim(ips(i))
ExitFunction
EndIf
Next
EndIf
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
EndFunction
</script>
完全的测试页面:
复制代码代码以下:
<%@PageLanguage="VB"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default"%>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<scriptrunat="server">
PublicFunctionCheckIp(ByValipAsString)AsBoolean
DimpatAsString="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
DimregAsRegex=NewRegex(pat)
ifip=""Then
CheckIp=False
exitFunction
endif
CheckIp=reg.IsMatch(ip)
EndFunction
PublicFunctionget_cli_ip()AsString
If(Not(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP")IsNothing)AndCheckIp(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP"))=True)Then
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP")
ExitFunction
ElseIfNot(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR")IsNothing)Then
Dimips()AsString=Split(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",")
ForiAsInteger=0Toips.Length-1
IfCheckIp(Trim(ips(i)))=TrueThen
get_cli_ip=Trim(ips(i))
ExitFunction
EndIf
Next
EndIf
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
EndFunction
</script>
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>UntitledPage</title>
</head>
<body>
<%
Dimclient_ipAsString=get_cli_ip()
System.Web.HttpContext.Current.Response.Write(client_ip)
%>
</body>
</html>
也不知道,我同学昨天说数据挖掘很好。 |
|