在线列表查看地理位置 for bbsxp 2007

By admin at 2007-07-18 • 0人收藏 • 396人看过

一、将下列文本保存为iptodz.asp,放在Utility目录下!


<%
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)
If IP="" Then Exit Function
 Dim Wry, IPType
 Set Wry = New TQQWry
 IPType = Wry.QQWry(IP)
 
 Select Case sType
  Case 1 GetIpInfoAv =  IP
  Case 2 GetIpInfoAv =  Wry.Country
  Case 3 GetIpInfoAv = Wry.LocalStr
  Case Else GetIpInfoAv =  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("database/CoralWry.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 = ""
  If InStr(LocalStr, "CZ88.NET") Then LocalStr = ""
 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
%>

 

二、打开ViewOnline.asp,找到
<!-- #include file="Setup.asp" -->
在下面添加
<!-- #include file="Utility/iptodz.asp" -->

三、找到

Sub default
 if Request.ServerVariables("Request_method") = "POST" and BestRole<>1 then error("只有超级版主与管理员才能使用查询功能")
 Key=HTMLEncode(Request.Form("Key"))
 Find=HTMLEncode(Request.Form("Find"))

 if Len(Find)>10 then error("非法操作")
 if Key<>empty then SqlFind=" where "&Find&"='"&Key&"'"
 sql="Select * from [BBSXP_UserOnline] "&SqlFind&" order by LastTime Desc"
 Rs.Open sql,Conn,1
  PageSetup=20 '设定每页的显示数量
  Rs.Pagesize=PageSetup
  TotalPage=Rs.Pagecount  '总页数
  PageCount = RequestInt("PageIndex")
  if PageCount <1 then PageCount = 1
  if PageCount > TotalPage then PageCount = TotalPage
  if TotalPage>0 then Rs.absolutePage=PageCount '跳转到指定页数
  i=0
  Do While Not Rs.EOF and i<PageSetup
   i=i+1
   if BestRole<>1 then
    ips=split(Rs("IPAddress"),".")
    ShowIP=""&ips(0)&"."&ips(1)&".*.*"
   else
    ShowIP=""&Rs("IPAddress")&""
   end if


   if ""&Rs("UserName")&""="" then
    UserName="<FONT COLOR=#C0C0C0>"&Rs("SessionID")&"</FONT>"
   else
    if Rs("IsInvisible")=0 or BestRole=1 then UserName="<a href=Profile.asp?UserName="&Rs("UserName")&">"&Rs("UserName")&"</a>"
    if Rs("IsInvisible")=1 then UserName=UserName&"(隐身)"
   end if


   place2=""
   if Rs("act")<>"" then
    place2 = "<a href="&Rs("acturl")&">"&Rs("act")&"</a>"
    place = "『 "&Rs("ForumName")&" 』"
   else
    place = "『 <a href="&Rs("acturl")&">"&Rs("ForumName")&"</a> 』"
   end if

   allline=""&allline&"<TR align=center id=CommonListCell><TD width=120>"&ShowIP&"</TD><TD width=120>"&Rs("cometime")&"</TD><TD width=120>"&UserName&"</TD><TD width=120>"&place&"</TD><TD height=24>"&place2&"</TD><TD width=120>"&Rs("lasttime")&"</TD></TR>"

   Rs.Movenext
  loop
 Rs.close
%>
<table cellspacing=1 cellpadding=5 width=100% id=CommonListArea>
 <tr align="center" id=CommonListTitle>
  <td width=120>IP地址</td>
  <td width=120>登录时间</td>
  <td width=120>用户</td>
  <td width=120>所在论坛</td>
  <td>所在主题</td>
  <td width=120>活动时间</td>
 </tr>
 <%=allline%>
</table>
<table cellspacing=0 cellpadding=0 border=0 width=100%>
 <tr>
  <td valign="top"><%ShowPage()%></td>

  <td align="right">
  <form action="ViewOnline.asp" method="POST">
   <select name=Find>
    <option value="UserName">查询用户</option>
    <option value="IPAddress">查询IP</option>
   </select> <input size="15" value="<%=Key%>" name="Key"> <input type="submit" value=" 确定 ">
  </form>
  </td>
 </tr>
</table>

替换成


Sub default
 if Request.ServerVariables("Request_method") = "POST" and BestRole<>1 then error("只有超级版主与管理员才能使用查询功能")
 Key=HTMLEncode(Request.Form("Key"))
 Find=HTMLEncode(Request.Form("Find"))

 if Len(Find)>10 then error("非法操作")
 if Key<>empty then SqlFind=" where "&Find&"='"&Key&"'"
 sql="Select * from [BBSXP_UserOnline] "&SqlFind&" order by LastTime Desc"
 Rs.Open sql,Conn,1
  PageSetup=20 '设定每页的显示数量
  Rs.Pagesize=PageSetup
  TotalPage=Rs.Pagecount  '总页数
  PageCount = RequestInt("PageIndex")
  if PageCount <1 then PageCount = 1
  if PageCount > TotalPage then PageCount = TotalPage
  if TotalPage>0 then Rs.absolutePage=PageCount '跳转到指定页数
  i=0
  Do While Not Rs.EOF and i<PageSetup
   i=i+1
   if BestRole<>1 then
    ips=split(Rs("IPAddress"),".")
    ShowIP=""&ips(0)&"."&ips(1)&"."&ips(2)&"."&ips(3)&""
   else
    ShowIP=""&Rs("IPAddress")&""
   end if


   if ""&Rs("UserName")&""="" then
    UserName="<FONT COLOR=#C0C0C0>"&Rs("SessionID")&"</FONT>"
   else
    if Rs("IsInvisible")=0 or BestRole=1 then UserName="<a href=Profile.asp?UserName="&Rs("UserName")&">"&Rs("UserName")&"</a>"
    if Rs("IsInvisible")=1 then UserName=UserName&"(隐身)"
   end if


   place2=""
   if Rs("act")<>"" then
    place2 = "<a href="&Rs("acturl")&">"&Rs("act")&"</a>"
    place = "『 "&Rs("ForumName")&" 』"
   else
    place = "『 <a href="&Rs("acturl")&">"&Rs("ForumName")&"</a> 』"
   end if

   allline=""&allline&"<TR align=center id=CommonListCell><TD width=120>"&ShowIP&"</TD><TD width=120>"&GetIpInfoAv(Rs("IPAddress"),0)&"</TD><TD width=120>"&UserName&"</TD><TD width=120>"&place&"</TD><TD height=24>"&place2&"</TD><TD>"&FormatDateTime(rs("cometime"),4)&"-"&FormatDateTime(rs("lasttime"),4)&"</TD></TR>"

   Rs.Movenext
  loop
 Rs.close
%>
<table cellspacing=1 cellpadding=5 width=100% id=CommonListArea>
 <tr align="center" id=CommonListTitle>
  <td width=120>IP地址</td>
  <td width=120>位于:</td>
  <td width=120>用户</td>
  <td width=120>所在论坛</td>
  <td>所在主题</td>
  <td width=120>登录-活动时间:</td>
 </tr>
 <%=allline%>
</table>
<table cellspacing=0 cellpadding=0 border=0 width=100%>
 <tr>
  <td valign="top"><%ShowPage()%></td>

  <td align="right">
  <form action="ViewOnline.asp" method="POST">
   <select name=Find>
    <option value="UserName">查询用户</option>
    <option value="IPAddress">查询IP</option>
   </select> <input size="15" value="<%=Key%>" name="Key"> <input type="submit" value=" 确定 ">
  </form>
  </td>
 </tr>
</table>


四、到网络上下载个珊瑚虫Ip数据库,将CoralWry.dat文件放在database目录下
OK!

[此帖子已被 admin 在 2007-10-7 14:42:34 编辑过]

2 个回复 | 最后更新于 2007-11-11
2007-10-07   #1
珊瑚虫Ip数据库下载地址

http://www.xdowns.com/soft/40/62/2006/Soft_31375.html

把解压出来的QQWry.Dat改名为CoralWry.dat

放在database目录下

就OK了

2007-11-11   #2

下来侃侃而谈

登录后方可回帖

登 录
信息栏
购买PHP虚拟主机 / VPS

Carbon Forum是一个基于话题的高性能轻型PHP论坛

下载地址:Carbon Forum v5.0.1
QQ群:12607708(QQ我不常上)

donate

手机支付宝扫描上方二维码可向本项目捐款

Loading...