【Asp技巧】ASP查询纯真数据库

admin 2021年4月3日19:10:43评论65 views字数 4804阅读16分0秒阅读模式

调用方法:


Function Look_Ip(IP)
 Dim Wry, IPType, QQWryVersion, IpCounter
 Set Wry = New TQQWry
 IPType = Wry.QQWry(IP)
 Look_Ip = Wry.Country & " " & Wry.LocalStr
End Function

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

Function WryInfo()
 Dim Wry, IPType, QQWry(1)
 Set Wry = New TQQWry
 IPType = Wry.QQWry("255.255.255.255")
 QQWry(0) = Wry.Country & " " & Wry.LocalStr
 QQWry(1) = Wry.RecordCount + 1
 WryInfo = QQWry
End Function

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("ScanIP.dat")
 End Sub

 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))
   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

 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

 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

 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
     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 = "114XP.CN"
  'If InStr(LocalStr, "CZ88.NET") Then LocalStr = "114XP.CN"
 End Sub

 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
   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

 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
   Country = "未知"
   QQWry = 2
   Exit Function
  End If
  
  RangB = 0
  RangE = RecordCount
  
  Do While (RangB
   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) 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
%>

文章来源于lcx.cc:【Asp技巧】ASP查询纯真数据库

相关推荐: 大家有考虑过微信公众平台的注入么

大家有考虑过微信公众平台的注入么 Valo洛洛 (tomorrow.) | 2013-08-08 19:04 RT [原文地址] 相关讨论: 1# Icyblade | 2013-08-08 19:09 你这个不是微信的问题吧 我手上也有个微信公众平台,工作流…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月3日19:10:43
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【Asp技巧】ASP查询纯真数据库https://cn-sec.com/archives/320100.html

发表评论

匿名网友 填写信息