⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cl_clsqqwry.asp

📁 淘客网上商店网站程序 淘客网上商店网站程序 淘客网上商店网站程序
💻 ASP
字号:
<%
'===================================================
' CreateLive CMS Version 5.0
'							Powered by Aspoo.CoM
'===================================================
' File: Cl_ClsQQWry.asp(来源:网络)
' Date: 2008-03-19
' Mail: Info@aspoo.cn
' Web : http://www.aspoo.com, http://www.aspoo.cn
' Bbs : http://bbs.aspoo.com, http://bbs.aspoo.cn
' Copyright (C) 2005-2008 Aspoo.Cn
'===================================================

'===================================================
'类名:Cls_QQWry
'查询:Cls_QQWry.QQWry(IP):返回值为数字(0=未找到;2=未知;3=正常)
'变量:Cls_QQWry.Country:国家地区字段
'变量:Cls_QQWry.LocalStr:省市及其他信息字段
'变量:Cls_QQWry.RecordCount:数据库IP地址数目(需加1)
'示例:
'---------------------------------------------------
'	Dim Wry, iType
'	Set Wry = New Cls_QQWry
'	iType = Wry.QQWry("192.168.1.111")
'	Select Case iType
'	Case 0
'		Response.write("未找到")
'	Case 2
'		Response.write(Wry.Country)
'	Case 3
'		Response.write(Wry.Country & Wry.LocalStr)
'	End Select
'	Set Wry = Nothing
'===================================================

Class Cls_QQWry
	Rem 变量声明变量
	Public Country, LocalStr, Buf, OffSet
	Private StartIP, EndIP, CountryFlag
	Public QQWryFile
	Public FirstStartIP, LastStartIP, RecordCount
	Private Stream, EndIPOff

	Rem 初始化变量
	Private Sub Class_Initialize
		Country = "" : LocalStr = ""
		StartIP = 0 : EndIP = 0
		CountryFlag = 0 : FirstStartIP = 0 
		LastStartIP = 0 : EndIPOff = 0 
		QQWryFile = Server.MapPath(InstallDir & "Data/QQWry.Dat")
		Set Stream = CreateObject("ADodb.Stream")
		Stream.Mode = 3
		Stream.Type = 1
	End Sub

	Rem 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

	Rem 整数逆转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

	Rem 获取开始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

	Rem 获取结束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

	Rem 获取地域信息,包含国家和和省市
	Private Sub GetCountry(IP)
		If (CountryFlag = 1 Or CountryFlag = 2) Then
			Country = GetFlagStr(EndIPOff + 4)
			If CountryFlag = 1 Then
				LocalStr = GetFlagStr(Stream.Position)
				Rem 以下用来获取数据库版本信息
				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
		Rem 过滤数据库中的无用信息
		Country = Trim(Country)
		LocalStr = Trim(LocalStr)
		If InStr(Country, "CZ88.NET") Then Country = ""
		If InStr(LocalStr, "CZ88.NET") Then LocalStr = ""
	End Sub

	Rem 获取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

	Rem 获取字串信息
	Private Function GetStr() 
		Dim c
		GetStr = ""
		Do While (True)
			c = AscB(Stream.Read(1))
			If (c = 0) Then Exit Do 
			Rem 如果是双字节,就进行高字节在结合低字节合成一个字符
			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

	Rem 核心函数,执行IP搜索
	Public Function QQWry(DotIP)
		Dim IP, nRet
		Dim RangB, RangE, RecNo
		If UBound(Split(DotIP,"."))<3 Then
			Country = "未知"
			QQWry = 2
			Exit Function
		End if
		IP = IPToInt (DotIP)
		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)
		Rem 在数据库中找不到任何IP地址
		If (RecordCount <= 1) Then
			Country = "未知"
			QQWry = 2
			Stream.Close : 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
			Rem 没有找到
			nRet = 0
		Else
			Rem 正常
			nRet = 3
		End If
		Call GetCountry(IP)
		Stream.Close
		QQWry = nRet
	End Function

	Private Sub Class_Terminate
		Set Stream = Nothing
	End Sub
End Class 
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -