时间:2016-02-15 22:21 来源: 我爱IT技术网 作者:佚名
欢迎您访问我爱IT技术网,今天小编为你分享的编程技术是:【asp.net(vb.net)获取真实IP的函数】,下面是详细的讲解!
asp.net(vb.net)获取真实IP的函数
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Public Function CheckIp(ByVal ip As String) As Boolean
Dim pat As String="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
Dim reg As Regex=New Regex(pat)
if ip="" Then
CheckIp=False
exit Function
end if
CheckIp=reg.IsMatch(ip)
End Function
Public Function get_cli_ip() As String
If ( Not( System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP") Is Nothing) And CheckIp(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP"))=True) Then
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("HTTP_CLIENT_IP")
Exit Function
ElseIf Not(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR") Is Nothing) Then
Dim ips() As String=Split(System.Web.HttpContext.Current.Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")
For i As Integer=0 To ips.Length - 1
If CheckIp(Trim(ips(i)))=True Then
get_cli_ip=Trim(ips(i))
Exit Function
End If
Next
End If
get_cli_ip=System.Web.HttpContext.Current.Request.ServerVariables("REMOTE_ADDR")
End Function
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<%
Dim client_ip As String=get_cli_ip()
System.Web.HttpContext.Current.Response.Write(client_ip)
%>
</body>
</html>
关于asp.net(vb.net)获取真实IP的函数的用户互动如下:
相关问题:asp.net怎么取得客户端真实IP。如果有代理则怎么取...
答:string IP=Request.ServerVariables["REMOTE_ADDR"]; >>详细
相关问题:Asp.net获得IP地址,看这一下这个函数怎么用?
答:可以试一下在Form Load 事件中写入如下代码: protected void Page_Load(object sender, EventArgs e) { LabIP.Text = getIP(this.Context) } >>详细
相关问题:vb.net如何使用TCP/IP协议向服务器发送字符串,要...
答:http://zhidao.baidu.com/question/44040206.html >>详细
- 【asp】asp.net url重写浅谈-net-url重写
- 【DataSet】DataSet、DataTable、DataRow区别详解
- 【asp】asp.net 动态添加多个用户控件-net-动态添
- 【创建】ASP.NET Web API教程 创建域模型的方法详
- 【asp】asp.net ubb使用代码-net-ubb使用
- 【默认图片】图片不存在使用默认图片代替的实例
- 【asp】asp.net 页面转向 Response.Redirect Ser
- 【页面打印】关于ASP.NET页面打印技术的常用方法
- 【MVC5】MVC 5 第一章 创建MVC 5 web应用程序-net
- 【MVC】一个简单MVC5 + EF6示例分享-EF6实例-MVC5
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
