📄 aspip所在地搜索.htm
字号:
Response.Write ("IP:" & IpSearch.IpAddress & "<BR>")
<BR> ' Response.Write ("IP转换为数值:" &
IpSearch.CLongIP(IpSearch.IpAddress) & "<BR>") <BR>
' Response.Write ("数值还原成IP:" &
IpSearch.CStringIP(IpSearch.CLongIP(IpSearch.IpAddress)) &
"<BR>") <BR> ' Response.Write ("<hr>") <BR>
' next <BR> ' next <BR> ' next
<BR> 'next <BR> %> <BR> <%
<BR> Class clsIpSearch <BR>
'##################################################################
<BR> '声明:本程序采用的数据为网络上著名的IP工具软件《追捕》作者“冯志宏” <BR>
'先生所精心搜集整理。 <BR> '《追捕》数据库的转换方法: <BR>
'修改wry.dll 文件后缀名称为 wry.dbf <BR> '方法一: <BR>
' 启动Access 数据,选择打开数据库,选择打开的文件类型为“dBASE 5 (*.dbf)” <BR>
' 打开wry.dbf文件,选择《工具》菜单下的《数据库实用工具》中的《转换数据库》 <BR> '
选择《转换为 Access 97 格式(版本可选)》功能,保存文件即可成为MDB格式。 <BR> '方法二:
<BR> ' 使用SQL Server提供的《导入和导出数据》向导。 <BR> '
方法简要说明:在ODBC 控制面板中设置指向wry.dbf的DSN。 <BR> '
使用《导入和导出数据》向导,选择其正确的驱动程序和要导入的库即可。 <BR> '
或者直接导入由方法一生成的MDB文件入库。 <BR> '方法三: <BR> '
使用Access 打开wry.dbf 文件后将自动通过MDB库引用原库数据。 <BR> ' <BR>
'未安装其他数据库平台,其他方法欠考虑。 <BR> '######################
类说明 #################################### <BR> '# IP
所在地搜索类 <BR> '# ConnectionString
为数据库连接声明,默认声明同级目录的wry.mdb <BR> '# IpAddress 请设置为进行搜索的IP
地址,默认取当前访问者IP <BR> '# 类建立方法 <BR> '# Dim
objVal '声明一个变量 <BR> '# Set objVal = New clsIpSearch
'建立类对象 <BR> '# Response.Write (objVal.IpAddress)
'显示当前访问者IP <BR> '# IP 搜索类方法列表: <BR> '#
.Valid_IP 'IP 地址正确性效验 <BR> '# 参数:IP 'IP 数值或者字符串
<BR> '# .CLongIP '将IP地址转换为长整型的数值 <BR> '#
参数:asNewIP '要转换的IP地址字符串 <BR> '# .CStringIP '将长整型的数值转换为IP
<BR> '# 参数:anNewIP '要还原为IP地址的数值 <BR> '#
.GetClientIP '取访问者的IP <BR> '# .GetIpAddrInfo
'得到设置过IpAddRess属性的IP所在地 <BR> '# 属性列表(自动初始化): <BR>
'# ConnEctionString 'ADo 访问数据库连接说明 <BR> '#
IpAddress '要操作的IP地址 <BR> '# 内部错误处理: <BR> '#
欠缺,未做,请自行补充。 <BR>
'##################################################################
<BR> <BR> Public ConnectionString
<BR> Public IpAddress <BR> Private DBConn
'连接对象,模块级声明 <BR> '────────────────────────────────
<BR> ' 类初始化 <BR> Private Sub
Class_initialize() <BR> ' 这里建立的是通过“数据转换--方法一”生成的mdb 库文件
<BR> ConnectionString="DRIVER={Microsoft Access Driver
(*.mdb)};DBQ=" & Server.MapPath("wry.mdb") <BR>
IpAddress = GetClientIP() <BR> Set DBConn =
OpenConnection() <BR> End Sub <BR>
'──────────────────────────────── <BR> ' 类注销 <BR>
Private Sub Class_Terminate() <BR>
ConnectionString = Null <BR> IpAddress = Null
<BR> DBConn.Close <BR> Set DBConn =
Nothing <BR> End Sub <BR>
'──────────────────────────────── <BR> ' 建立一个连接
<BR> Private Function OpenConnection() <BR>
Dim tmpConn <BR> Set
tmpConn=Server.CreateObject("ADODB.Connection") <BR>
tmpConn.Open ConnectionString <BR> Set
OpenConnection=tmpConn <BR> Set tmpConn=nothing
<BR> End Function <BR>
'──────────────────────────────── <BR> '
执行一个SQL命令,并返回一个数据集对象 <BR> Private Function
SQLExeCute(strSql) <BR> Dim Rs <BR> Set
Rs=DBConn.ExeCute(strSQL) <BR> Set SQLExeCute = Rs
<BR> Set Rs=nothing <BR> End Function
<BR> '──────────────────────────────── <BR>
'IP 效验 <BR> Public Function Valid_IP(ByVal IP)
<BR> Dim i <BR> Dim dot_count <BR>
Dim test_octet <BR> Dim byte_check <BR>
IP = Trim(IP) <BR> ' 确认IP长度 <BR> If
Len(IP) < &H08 Then <BR> Valid_IP = False
<BR> '显示错误提示 <BR> Exit Function <BR>
End If <BR> <BR> i = &H01
<BR> dot_count = &H00 <BR> For i = 1
To Len(IP) <BR> If Mid(IP, i, &H01) = "." Then
<BR> ' 增加点的记数值 <BR> ' 并且设置text_octet 值为空
<BR> dot_count = dot_count + &H01 <BR>
test_octet = "" <BR> If i = Len(IP) Then <BR>
' 如果点在结尾则IP效验失败 <BR> Valid_IP = False <BR>
' 显示错误提示 <BR> Exit Function <BR>
End If <BR> Else <BR> test_octet =
test_octet & Mid(IP, i, &H01) <BR> '
使用错误屏蔽来检查数据段值的正确性 <BR> On Error Resume Next <BR>
' 进行强制类型转换 <BR> ' 如果转换失败就可通过检查Err是否为真来确认
<BR> byte_check = CByte(test_octet) <BR>
If (Err) Then <BR> ' 强制类型转换产生错误 <BR> '
所取段值的数据不为数值 <BR> ' 或所取段值的数据长度大于&HFF <BR>
' 则类型不为byte类型 <BR> ' IP 地址的正确性为假 <BR>
Valid_IP = False <BR> Exit Function <BR>
End If <BR> End If <BR> Next
<BR> <BR> ' 通过上一步的验证,现在应该要检查小点是否有3个
<BR> If dot_count <> &H03 Then <BR>
Valid_IP = False <BR> Exit Function <BR>
End If <BR> ' 一切正常,那么该IP为正确的IP地址 <BR>
Valid_IP = True <BR> End Function <BR>
'──────────────────────────────── <BR> '
转换一个数值为IP <BR> Public Function CStringIP(ByVal anNewIP)
<BR> Dim lsResults <BR> Dim lnTemp
<BR> Dim lnIndex <BR> For lnIndex =
&H03 To &H00 Step -&H01 <BR> lnTemp =
Int(anNewIP / (&H100 ^ lnIndex)) <BR> lsResults =
lsResults & lnTemp & "." <BR> anNewIP = anNewIP
- (lnTemp * (&H100 ^ lnIndex)) <BR> Next <BR>
lsResults = Left(lsResults, Len(lsResults) - &H01)
<BR> CStringIP = lsResults <BR> End
function <BR> '────────────────────────────────
<BR> ' 转换一个IP到数值 <BR> Public Function
CLongIP(ByVal asNewIP) <BR> Dim lnResults <BR>
Dim lnIndex <BR> Dim lnIpAry <BR>
lnIpAry = Split(asNewIP, ".", &H04) <BR> For
lnIndex = &H00 To &H03 <BR> if Not lnIndex =
&H03 Then <BR> lnIpAry(lnIndex) = lnIpAry(lnIndex)
* (&H100 ^ (&H03 - lnIndex)) <BR> End if
<BR> lnResults = lnResults + lnIpAry(lnIndex)
<BR> Next <BR> CLongIP = lnResults
<BR> End function <BR>
'──────────────────────────────── <BR> ' 取Client IP
<BR> Public Function GetClientIP() <BR>
dim uIpAddr <BR> ' 本函数参考webcn.Net/AspHouse
文献<取真实的客户IP> <BR> uIpAddr =
Request.ServerVariables("HTTP_X_FORWARDED_FOR") <BR> If
uIpAddr = "" Then uIpAddr = Request.ServerVariables("REMOTE_ADDR")
<BR> GetClientIP = uIpAddr <BR> uIpAddr =
"" <BR> End function <BR>
'──────────────────────────────── <BR> ' 读取IP所在地的信息
<BR> Public function GetIpAddrInfo() <BR>
Dim tmpIpAddr <BR> Dim IpAddrVal <BR> Dim
ic,charSpace <BR> Dim tmpSQL <BR>
charSpace = "" <BR> IpAddrVal = IpAddress <BR>
If Not Valid_IP(IpAddrVal) Then <BR>
GetIpAddrInfo =NULL <BR> Exit Function <BR>
End If <BR> '将IP字符串劈开成数组好进行处理 <BR>
tmpIpAddr = Split(IpAddrVal,".",-1,1) <BR> For ic =
&H00 To Ubound(tmpIpAddr) <BR> '补位操作,保证每间隔满足3个字符
<BR> Select Case Len(tmpIpAddr(ic)) <BR>
Case &H01 :charSpace = "00" <BR> Case &H02
:charSpace = "0" <BR> Case Else :charSpace = ""
<BR> End Select <BR> tmpIpAddr(ic) =
charSpace & tmpIpAddr(ic) <BR> Next <BR>
IpAddrVal = tmpIpAddr(&H00) & "." &
tmpIpAddr(&H01) & "." & tmpIpAddr(&H02) & "."
& tmpIpAddr(&H03) <BR> <BR>
'以下为查询,IP地址库基于《追捕》的IP数据库,感谢"冯志宏"先生的贡献 <BR> '库结构如下:
<BR> 'CREATE TABLE [dbo].[wry] ( <BR> '
[STARTIP] [nvarchar] (17) COLLATE Chinese_PRC_CI_AS NULL , --起始IP段
<BR> ' [ENDIP] [nvarchar] (17) COLLATE
Chinese_PRC_CI_AS NULL , --终止IP段 <BR> ' [COUNTRY]
[nvarchar] (16) COLLATE Chinese_PRC_CI_AS NULL , --国家或者地区 <BR>
' [LOCAL] [nvarchar] (54) COLLATE Chinese_PRC_CI_AS NULL ,
--本地地址 <BR> ' [THANK] [nvarchar] (23) COLLATE
Chinese_PRC_CI_AS NULL --感谢修正IP地址用户姓名 <BR> ') ON
[PRIMARY] <BR> '经过分析库的数据存放结构,总结出准确的查询方法,具体看下面的查询过程
<BR> tmpSQL = "select * from wry where (startIP<='"
& IpAddrVal & "') and (ENDIP>='" & IpAddrVal &
"') " & _ <BR> " and left(startIP," &
Len(tmpIpAddr(&H00)) & ") = '" & tmpIpAddr(&H00)
& "'" & _ <BR> " and left(endip," &
Len(tmpIpAddr(&H00)) & ")='" & tmpIpAddr(&H00) &
"'" <BR> charSpace = GetDbIpInfo(tmpSQL) <BR>
If Len(charSpace)=&H00 Then <BR>
GetIpAddrInfo = NULL <BR> Else <BR>
GetIpAddrInfo = charSpace <BR> End If <BR>
charSpace = Null <BR> tmpSQL = Null <BR>
end function <BR> '────────────────────────────────
<BR> ' 返回数据查询的字符串 <BR> Private function
GetDbIpInfo(byVal sql) <BR> Dim OpenIpSearchRs
<BR> Dim result <BR> Set OpenIpSearchRs =
SQLExeCute(sql) <BR> If Not OpenIpSearchRs.Eof Then
<BR> result = NullToSpace(OpenIpSearchRs("COUNTRY"))
& "," & NullToSpace(OpenIpSearchRs("LOCAL")) & "," &
NullToSpace(OpenIpSearchRs("THANK")) <BR> Else
<BR> result = NULL <BR> End If <BR>
OpenIpSearchRs.Close <BR> Set
OpenIpSearchRs=Nothing <BR> GetDbIpInfo = result
<BR> End function <BR>
'──────────────────────────────── <BR> ' 将数据库空记录转换为空字符
<BR> Private function NullToSpace(byVal rsStr)
<BR> If isNull(rsStr) Then <BR>
NullToSpace = "" <BR> Else <BR>
NullToSpace = Trim(rsStr) <BR> End If <BR>
End Function <BR> End Class <BR> %>
<BR> <BR> <BR></TD></TR>
<TR>
<TD width="100%">
<DIV align=right><INPUT name=button onclick="document.location.href='javascript:sendmail(853)'" type=button value=推荐给朋友>
<INPUT name=button onclick=javascript:window.print() type=button value=打印本页>
<INPUT name=button onclick=window.close() type=button value=关闭窗口></DIV></TD></TR>
<TR>
<TD width="100%">
<HR noShade SIZE=1>
</TD></TR>
<TR>
<TD class=review width="100%">在此发表你对本文的意见和看法(800字以内) <A
href="javascript:document.review.submit()">发表</A></TD></TR>
<TR>
<TD class=review width="100%"><IMG height=5
src="ASPIP所在地搜索 - 者网摘.files/space.gif" width=1></TD></TR>
<TR>
<FORM action=review.cgi name=review>
<TD class=review width=590><TEXTAREA cols=70 name=text rows=5></TEXTAREA> <INPUT
name=action type=hidden value=new> <INPUT name=id type=hidden
value=853> </TD></FORM></TR>
<TR>
<TD class=review width="100%"><IMG height=5
src="ASPIP所在地搜索 - 者网摘.files/space.gif" width=1></TD></TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -