ASP环境中使用QQ纯真版IP数据库QQWry.dat
来源:asp之家 发布时间:2010-02-26 13:35:00
QQWry.dat数据可以去百度搜索最新版本
<%
'=========================================================
' QQWry.DAT 利用程序 修改自互联网流传代码
' 本类在ASP环境中使用纯真版QQWry.dat通过完美测试
' 如果您的服务器环境不支持ADodb.Stream,将无法使用此程序
' 推荐使用纯真数据库,更新也方便
' ========================================================
' ============================================
' 返回IP信息
' ============================================
Function Look_Ip(IP)
Dim Wry, IPType, QQWryVersion, IpCounter
' 设置类对象
Set Wry = New TQQWry
' 开始搜索,并返回搜索结果
' 您可以根据 QQWry(IP) 返回值来判断该IP地址在数据库中是否存在,如果不存在可以执行其他的一些操作
' 比如您自建一个数据库作为追捕等,这里我就不详细说明了
IPType = Wry.QQWry(IP)
' Country:国家地区字段
' LocalStr:省市及其他信息字段
Look_Ip = Wry.Country & " " & Wry.LocalStr
End Function
' ============================================
' 返回IP信息 JS调用
' ============================================
Function GetIpInfoAv(IP, sType)
Dim Wry, IPType
Set Wry = New TQQWry
IPType = Wry.QQWry(IP)
Select Case sType
Case 1 GetIpInfoAv = "document.write(""" & IP & """);"
Case 2 GetIpInfoAv = "document.write(""" & Wry.Country & """);"
Case 3 GetIpInfoAv = "document.write(""" & Wry.LocalStr & """);"
Case Else GetIpInfoAv = "document.write(""您来自:" & IP & " 所在区域:" & Wry.Country & " " & Wry.LocalStr & """);"
End Select
End Function
' ============================================
' 返回QQWry信息
' ============================================
Function WryInfo()
Dim Wry, IPType, QQWry(1)
' 设置类对象
Set Wry = New TQQWry
IPType = Wry.QQWry("255.255.255.255")
' 读取数据库版本信息
QQWry(0) = Wry.Country & " " & Wry.LocalStr
' 读取数据库IP地址数目
QQWry(1) = Wry.RecordCount + 1
WryInfo = QQWry
End Function
' ============================================
' 侠情江湖IP物理定位搜索类
' ============================================
Class TQQWry
' ============================================
' 变量声名
' ============================================
Dim Country, LocalStr, Buf, OffSet
Private StartIP, EndIP, CountryFlag
Public QQWryFile
Public FirstStartIP, LastStartIP, RecordCount
Private Stream, EndIPOff
' ============================================
' 类模块初始化
' ============================================
Private Sub Class_Initialize
Country = ""
LocalStr = ""
StartIP = 0
EndIP = 0
CountryFlag = 0
FirstStartIP = 0
LastStartIP = 0
EndIPOff = 0
QQWryFile = Server.MapPath("QQWry.dat") 'QQ IP库路径,要转换成物理路径
End Sub
' ============================================
' IP地址转换成整数
' ============================================
Function IPToInt(IP)
Dim IPArray, i
IPArray = Split(IP, ".", -1)
FOr i = 0 to 3
If Not IsNumeric(IPArray(i)) Then IPArray(i) = 0
If CInt(IPArray(i)) < 0 Then IPArray(i) = Abs(CInt(IPArray(i)))
If CInt(IPArray(i)) > 255 Then IPArray(i) = 255
Next
IPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3))
End Function
' ============================================
' 整数逆转IP地址
' ============================================
Function IntToIP(IntValue)
p4 = IntValue - Fix(IntValue/256)*256
IntValue = (IntValue-p4)/256
p3 = IntValue - Fix(IntValue/256)*256
IntValue = (IntValue-p3)/256
p2 = IntValue - Fix(IntValue/256)*256
IntValue = (IntValue - p2)/256
p1 = IntValue
IntToIP = Cstr(p1) & "." & Cstr(p2) & "." & Cstr(p3) & "." & Cstr(p4)
End Function
' ============================================
' 获取开始IP位置
' ============================================
Private Function GetStartIP(RecNo)
OffSet = FirstStartIP + RecNo * 7
Stream.Position = OffSet
Buf = Stream.Read(7)
EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256)
StartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
GetStartIP = StartIP
End Function
' ============================================
' 获取结束IP位置
' ============================================
Private Function GetEndIP()
Stream.Position = EndIPOff
Buf = Stream.Read(5)
EndIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
CountryFlag = AscB(MidB(Buf, 5, 1))
GetEndIP = EndIP
End Function
' ============================================
' 获取地域信息,包含国家和和省市
' ============================================
Private Sub GetCountry(IP)
If (CountryFlag = 1 Or CountryFlag = 2) Then
Country = GetFlagStr(EndIPOff + 4)
If CountryFlag = 1 Then
LocalStr = GetFlagStr(Stream.Position)
' 以下用来获取数据库版本信息
If IP >= IPToInt("255.255.255.0") And IP <= IPToInt("255.255.255.255") Then
LocalStr = GetFlagStr(EndIPOff + 21)
Country = GetFlagStr(EndIPOff + 12)
End If
Else
LocalStr = GetFlagStr(EndIPOff + 8)
End If
Else
Country = GetFlagStr(EndIPOff + 4)
LocalStr = GetFlagStr(Stream.Position)
End If
' 过滤数据库中的无用信息
Country = Trim(Country)
LocalStr = Trim(LocalStr)
'If InStr(Country, "CZ88.NET") Then Country = "aspxhome.com"
'If InStr(LocalStr, "CZ88.NET") Then LocalStr = "aspxhome.com"
End Sub
' ============================================
' 获取IP地址标识符
' ============================================
Private Function GetFlagStr(OffSet)
Dim Flag
Flag = 0
Do While (True)
Stream.Position = OffSet
Flag = AscB(Stream.Read(1))
If(Flag = 1 Or Flag = 2 ) Then
Buf = Stream.Read(3)
If (Flag = 2 ) Then
CountryFlag = 2
EndIPOff = OffSet - 4
End If
OffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)
Else
Exit Do
End If
Loop
If (OffSet < 12 ) Then
GetFlagStr = ""
Else
Stream.Position = OffSet
GetFlagStr = GetStr()
End If
End Function
' ============================================
' 获取字串信息
' ============================================
Private Function GetStr()
Dim c
GetStr = ""
Do While (True)
c = AscB(Stream.Read(1))
If (c = 0) Then Exit Do
'如果是双字节,就进行高字节在结合低字节合成一个字符
If c > 127 Then
If Stream.EOS Then Exit Do
GetStr = GetStr & Chr(AscW(ChrB(AscB(Stream.Read(1))) & ChrB(C)))
Else
GetStr = GetStr & Chr(c)
End If
Loop
End Function
' ============================================
' 核心函数,执行IP搜索
' ============================================
Public Function QQWry(DotIP)
Dim IP, nRet
Dim RangB, RangE, RecNo
IP = IPToInt (DotIP)
Set Stream = CreateObject("ADodb.Stream")
Stream.Mode = 3
Stream.Type = 1
Stream.Open
Stream.LoadFromFile QQWryFile
Stream.Position = 0
Buf = Stream.Read(8)
FirstStartIP = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256) + (AscB(MidB(Buf, 4, 1))*256*256*256)
LastStartIP = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256) + (AscB(MidB(Buf, 8, 1))*256*256*256)
RecordCount = Int((LastStartIP - FirstStartIP)/7)
' 在数据库中找不到任何IP地址
If (RecordCount <= 1) Then
Country = "未知"
QQWry = 2
Exit Function
End If
RangB = 0
RangE = RecordCount
Do While (RangB < (RangE - 1))
RecNo = Int((RangB + RangE)/2)
Call GetStartIP (RecNo)
If (IP = StartIP) Then
RangB = RecNo
Exit Do
End If
If (IP > StartIP) Then
RangB = RecNo
Else
RangE = RecNo
End If
Loop
Call GetStartIP(RangB)
Call GetEndIP()
If (StartIP <= IP) And ( EndIP >= IP) Then
' 没有找到
nRet = 0
Else
' 正常
nRet = 3
End If
Call GetCountry(IP)
QQWry = nRet
End Function
' ============================================
' 类终结
' ============================================
Private Sub Class_Terminate
On ErrOr Resume Next
Stream.Close
If Err Then Err.Clear
Set Stream = Nothing
End Sub
End Class
%>
调用:
<%ip_str="要查询的IP"%>
<%=look_ip(ip_str)%>
<SCRIPT LANGUAGE="JavaScript">
<!--
<%=GetIpInfoAv(ip_str, 0) '可以选1,2,3%>
//-->
</SCRIPT>
QQWry.dat数据可以去百度搜索最新版本
调用:
新建一个页面
<!--#include file="IP.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>IP查询 - asp之家</title>
</head>
<body>
调用:<br>
<%ip_str="218.6.31.132"%>
<%=look_ip(ip_str)%><br>
<SCRIPT LANGUAGE="JavaScript">
<%=GetIpInfoAv(ip_str, 0)%>
</SCRIPT>
</body>
</html>
猜你喜欢
- 在许多人看来,HTML应该是WEB制作所有语言中最简单的语言,因为它不需要编译、封闭等,甚至只需要一个记事本就可以让其在浏览器中呈现出来。所
- 首先先发一下我的项目路径1. 首先要下载 sass-resources-loadernpm install sass
- python3.0 模拟用户登录,三次错误锁定的实例实例如下所示:# -*- coding:utf-8 -*-#需求模拟用户登录,超过三次错
- 如何导入数据库 可以从限制文件中导入SQL共享服务器数据库。如果想把存放在其他地方的数据导入,需要先把其内容拷到限制文件中。(注:在导入数据
- 1. 查看数据库的版本select @@version2.查看数据库所在机器操作系统参数exec master..xp_msver3. 查看
- 有两种方法供参考.一种是实实在在的将图片先用ASPJPEG组件做成想要的尺寸,再读取好处是节省服务器带宽,速度快坏处是处理起来较为麻烦,并网
- 在 Python 的项目中,如何管理所用的全部依赖库呢?最主流的做法是维护一份“requirements.txt”,记录下依赖库的名字及其版
- 插件下载:blueideasearch.xpi首先第一步 说一下怎么样查看firefox插件的源码, 就我上边写的那个东西,把它下载下来.将
- 安装使用pip install XlsxWriter来安装,Xlsxwriter用来创建excel表格,功能很强大,下面具体介绍:1.简单使
- Web技术的发展速度太快了,如果你不与时俱进,就会被淘汰。因此,为了应对即将到来的HTML5,本文总结了22个HTML5的初级技巧,希望能对
- 要写爬虫爬取大量的数据,就会面临ip被封的问题,虽然可以通过设置延时的方法来延缓对网站的访问,但是一旦访问次数过多仍然会面临ip被封的风险,
- 傅里叶变换dft = cv.dft(np.float32(img),flags = cv.DFT_COMPLEX_OUTPUT)傅里叶逆变换
- 场景说明假设有一个mysql表被水平切分,分散到多个host中,每个host拥有n个切分表。 如果需要并发去访问这些表,快速得到查询结果,
- __author__ = 'clownfish'#coding:utf-8import urllib2,urllib,coo
- K-Means聚类算法介绍K-Means又称为K均值聚类算法,属于聚类算法中的一种,而聚类算法在机器学习算法中属于无监督学习,在业务中常常会
- 一、切片切片:指对操作的对象截取其中一部分的操作,字符串、列表、元组都支持切片操作语法:序列[开始位置下标:结束位置下标:步长] ,不包含结
- 前言在写程序时,我们会经常碰到程序出现异常,这时候我们就不得不处理这些异常,以保证程序的健壮性。处理异常的版本有以下几种,你通常的做法是哪种
- 什么是python的装饰器?网络上的定义:装饰器就是一函数,用来包装函数的函数,用来修饰原函数,将其重新赋值给原来的标识符,并永久的丧失原函
- 1、下载MySQL官方的mysql-connector-python-8.0.17-py3.7-windows-x86-64bit.msi,
- 1、动态sql, 即动态参数:在存储过程中,想要直接用表名变量做参数,动态执行sql,不能直接写<P>create proced