预览模式: 普通 | 列表

Asp读取调用纯真IP数据库

ASP/Visual Basic代码
  1. <%   
  2. '文件名:ip.asp 与QQwry.dat放在一个文件夹下面   
  3. '使用:在要用到的查询ip的asp页面中最前面加入<!--#include file = "ip.asp"-->   
  4. '然后可以用address(getIP())获得请求的地理位置   
  5.   
  6. '=========================================================   
  7. ' IP物理定位搜索类 Version 3.0.0   
  8. ' QQWry.DAT 利用程序 修改自互联网流传代码   
  9. ' 本类在ASP环境中使用纯真版QQWry.dat通过完美测试   
  10. ' 如果您的服务器环境不支持ADodb.Stream,将无法使用此程序   
  11. ' 推荐使用纯真数据库,更新也方便   
  12. ' ========================================================   
  13.   
  14. ' ============================================   
  15. ' 返回IP信息   
  16. ' 如address("127.0.0.1")   
  17. ' 返回值为:"本机地址 CZ88.NET"   
  18. ' ============================================   
  19. Function address(sip)   
  20. Dim Wry, IPType   
  21. Set Wry = New TQQWry   
  22. IPType = Wry.QQWry(sip)   
  23.   
  24. address=""&Wry.Country & " " & Wry.LocalStr &""   
  25. End Function   
  26.   
  27. '获得请求的实际IP地址   
  28. Function getIP()   
  29. Dim strIPAddr   
  30. If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then   
  31. strIPAddr = Request.ServerVariables("REMOTE_ADDR")   
  32. ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then   
  33. strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)   
  34. ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then   
  35. strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)   
  36. Else   
  37. strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")   
  38. End If   
  39. getIP = Trim(Mid(strIPAddr, 1, 30))   
  40. End Function   
  41.   
  42. Function Look_Ip(IP)   
  43. Dim Wry, IPType, QQWryVersion, IpCounter   
  44. ' 设置类对象   
  45. Set Wry = New TQQWry   
  46. ' 开始搜索,并返回搜索结果   
  47. ' 您可以根据 QQWry(IP) 返回值来判断该IP地址在数据库中是否存在,如果不存在可以执行其他的一些操作   
  48. ' 比如您自建一个数据库作为追捕等,这里我就不详细说明了   
  49. IPType = Wry.QQWry(IP)   
  50. ' Country:国家地区字段   
  51. ' LocalStr:省市及其他信息字段   
  52. Look_Ip = Wry.Country & " " & Wry.LocalStr   
  53. End Function   
  54. ' ============================================   
  55. ' 返回IP信息 JS调用   
  56. ' ============================================   
  57. Function GetIpInfoAv(IP, sType)   
  58. Dim Wry, IPType   
  59. Set Wry = New TQQWry   
  60. IPType = Wry.QQWry(IP)   
  61.   
  62. Select Case sType   
  63. Case 1 GetIpInfoAv = "document.write(""" & IP & """);"   
  64. Case 2 GetIpInfoAv = "document.write(""" & Wry.Country & """);"   
  65. Case 3 GetIpInfoAv = "document.write(""" & Wry.LocalStr & """);"   
  66. Case Else GetIpInfoAv = "document.write(""您来自:" & IP & " 所在区域:" & Wry.Country & " " & Wry.LocalStr & """);"   
  67. End Select   
  68. End Function   
  69. ' ============================================   
  70. ' 返回QQWry信息   
  71. ' ============================================   
  72. Function WryInfo()   
  73. Dim Wry, IPType, QQWry(1)   
  74. ' 设置类对象   
  75. Set Wry = New TQQWry   
  76. IPType = Wry.QQWry("255.255.255.255")   
  77. ' 读取数据库版本信息   
  78. QQWry(0) = Wry.Country & " " & Wry.LocalStr   
  79. ' 读取数据库IP地址数目   
  80. QQWry(1) = Wry.RecordCount + 1   
  81. WryInfo = QQWry   
  82. End Function   
  83. ' ============================================   
  84. ' 爱雪儿IP物理定位搜索类   
  85. ' ============================================   
  86. Class TQQWry   
  87. ' ============================================   
  88. ' 变量声名   
  89. ' ============================================   
  90. Dim Country, LocalStr, Buf, OffSet   
  91. Private StartIP, EndIP, CountryFlag   
  92. Public QQWryFile   
  93. Public FirstStartIP, LastStartIP, RecordCount   
  94. Private Stream, EndIPOff   
  95. ' ============================================   
  96. ' 类模块初始化   
  97. ' ============================================   
  98. Private Sub Class_Initialize   
  99. Country = ""   
  100. LocalStr = ""   
  101. StartIP = 0   
  102. EndIP = 0   
  103. CountryFlag = 0   
  104. FirstStartIP = 0   
  105. LastStartIP = 0   
  106. EndIPOff = 0   
  107. QQWryFile = Server.MapPath("QQWry.dat"'QQ IP库路径,要转换成物理路径   
  108. End Sub   
  109. ' ============================================   
  110. ' IP地址转换成整数   
  111. ' ============================================   
  112. Function IPToInt(IP)   
  113. Dim IPArray, i   
  114. IPArray = Split(IP, ".", -1)   
  115. FOr i = 0 to 3   
  116. If Not IsNumeric(IPArray(i)) Then IPArray(i) = 0   
  117. If CInt(IPArray(i)) < 0 Then IPArray(i) = Abs(CInt(IPArray(i)))   
  118. If CInt(IPArray(i)) > 255 Then IPArray(i) = 255   
  119. Next   
  120. IPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3))   
  121. End Function   
  122. ' ============================================   
  123. ' 整数逆转IP地址   
  124. ' ============================================   
  125. Function IntToIP(IntValue)   
  126. p4 = IntValue - Fix(IntValue/256)*256   
  127. IntValue = (IntValue-p4)/256   
  128. p3 = IntValue - Fix(IntValue/256)*256   
  129. IntValue = (IntValue-p3)/256   
  130. p2 = IntValue - Fix(IntValue/256)*256   
  131. IntValue = (IntValue - p2)/256   
  132. p1 = IntValue   
  133. IntToIP = Cstr(p1) & "." & Cstr(p2) & "." & Cstr(p3) & "." & Cstr(p4)   
  134. End Function   
  135. ' ============================================   
  136. ' 获取开始IP位置   
  137. ' ============================================   
  138. Private Function GetStartIP(RecNo)   
  139. OffSet = FirstStartIP + RecNo * 7   
  140. Stream.Position = OffSet   
  141. Buf = Stream.Read(7)   
  142.   
  143. EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256)   
  144. 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)   
  145. GetStartIP = StartIP   
  146. End Function   
  147. ' ============================================   
  148. ' 获取结束IP位置   
  149. ' ============================================   
  150. Private Function GetEndIP()   
  151. Stream.Position = EndIPOff   
  152. Buf = Stream.Read(5)   
  153. 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)   
  154. CountryFlag = AscB(MidB(Buf, 5, 1))   
  155. GetEndIP = EndIP   
  156. End Function   
  157. ' ============================================   
  158. ' 获取地域信息,包含国家和和省市   
  159. ' ============================================   
  160. Private Sub GetCountry(IP)   
  161. If (CountryFlag = 1 Or CountryFlag = 2) Then   
  162. Country = GetFlagStr(EndIPOff + 4)   
  163. If CountryFlag = 1 Then   
  164. LocalStr = GetFlagStr(Stream.Position)   
  165. ' 以下用来获取数据库版本信息   
  166. If IP >= IPToInt("255.255.255.0"And IP <= IPToInt("255.255.255.255"Then   
  167. LocalStr = GetFlagStr(EndIPOff + 21)   
  168. Country = GetFlagStr(EndIPOff + 12)   
  169. End If   
  170. Else   
  171. LocalStr = GetFlagStr(EndIPOff + 8)   
  172. End If   
  173. Else   
  174. Country = GetFlagStr(EndIPOff + 4)   
  175. LocalStr = GetFlagStr(Stream.Position)   
  176. End If   
  177. ' 过滤数据库中的无用信息   
  178. Country = Trim(Country)   
  179. LocalStr = Trim(LocalStr)   
  180. If InStr(Country, "CZ88.NET"Then Country = "114XP.CN"   
  181. If InStr(LocalStr, "CZ88.NET"Then LocalStr = "114XP.CN"   
  182. End Sub   
  183. ' ============================================   
  184. ' 获取IP地址标识符   
  185. ' ============================================   
  186. Private Function GetFlagStr(OffSet)   
  187. Dim Flag   
  188. Flag = 0   
  189. Do While (True)   
  190. Stream.Position = OffSet   
  191. Flag = AscB(Stream.Read(1))   
  192. If(Flag = 1 Or Flag = 2 ) Then   
  193. Buf = Stream.Read(3)   
  194. If (Flag = 2 ) Then   
  195. CountryFlag = 2   
  196. EndIPOff = OffSet - 4   
  197. End If   
  198. OffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)   
  199. Else   
  200. Exit Do   
  201. End If   
  202. Loop   
  203.   
  204. If (OffSet < 12 ) Then   
  205. GetFlagStr = ""   
  206. Else   
  207. Stream.Position = OffSet   
  208. GetFlagStr = GetStr()   
  209. End If   
  210. End Function   
  211. ' ============================================   
  212. ' 获取字串信息   
  213. ' ============================================   
  214. Private Function GetStr()   
  215. Dim c   
  216. GetStr = ""   
  217. Do While (True)   
  218. c = AscB(Stream.Read(1))   
  219. If (c = 0) Then Exit Do   
  220.   
  221. '如果是双字节,就进行高字节在结合低字节合成一个字符   
  222. If c > 127 Then   
  223. If Stream.EOS Then Exit Do   
  224. GetStr = GetStr & Chr(AscW(ChrB(AscB(Stream.Read(1))) & ChrB(C)))   
  225. Else   
  226. GetStr = GetStr & Chr(c)   
  227. End If   
  228. Loop   
  229. End Function   
  230. ' ============================================   
  231. ' 核心函数,执行IP搜索   
  232. ' ============================================   
  233. Public Function QQWry(DotIP)   
  234. Dim IP, nRet   
  235. Dim RangB, RangE, RecNo   
  236.   
  237. IP = IPToInt (DotIP)   
  238.   
  239. Set Stream = CreateObject("ADodb.Stream")   
  240. Stream.Mode = 3   
  241. Stream.Type = 1   
  242. Stream.Open   
  243. Stream.LoadFromFile QQWryFile   
  244. Stream.Position = 0   
  245. Buf = Stream.Read(8)   
  246.   
  247. 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)   
  248. 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)   
  249. RecordCount = Int((LastStartIP - FirstStartIP)/7)   
  250. ' 在数据库中找不到任何IP地址   
  251. If (RecordCount <= 1) Then   
  252. Country = "未知"   
  253. QQWry = 2   
  254. Exit Function   
  255. End If   
  256.   
  257. RangB = 0   
  258. RangE = RecordCount   
  259.   
  260. Do While (RangB < (RangE - 1))   
  261. RecNo = Int((RangB + RangE)/2)   
  262. Call GetStartIP (RecNo)   
  263. If (IP = StartIP) Then   
  264. RangB = RecNo   
  265. Exit Do   
  266. End If   
  267. If (IP > StartIP) Then   
  268. RangB = RecNo   
  269. Else   
  270. RangE = RecNo   
  271. End If   
  272. Loop   
  273.   
  274. Call GetStartIP(RangB)   
  275. Call GetEndIP()   
  276.   
  277. If (StartIP <= IP) And ( EndIP >= IP) Then   
  278. ' 没有找到   
  279. nRet = 0   
  280. Else   
  281. ' 正常   
  282. nRet = 3   
  283. End If   
  284. Call GetCountry(IP)   
  285.   
  286. QQWry = nRet   
  287. End Function   
  288. ' ============================================   
  289. ' 类终结   
  290. ' ============================================   
  291. Private Sub Class_Terminate   
  292. On ErrOr Resume Next   
  293. Stream.Close   
  294. If Err Then Err.Clear   
  295. Set Stream = Nothing   
  296. End Sub   
  297. End Class   
  298. %>  

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2894

Asp截取中文字符

ASP/Visual Basic代码
  1. Function GetStringLength(txt,length)  
  2. dim i  
  3. i=1  
  4. y=0  
  5. txt=trim(txt)  
  6. for i=1 to len(txt)  
  7. j=mid(txt,i,1)  
  8. if asc(j)>=0 and asc(j)<=127 then '汉字外的其他符号,如:!@#,数字,大小写英文字母  
  9. y=y+0.5  
  10. else '汉字  
  11. y=y+1  
  12. end if  
  13. if -int(-y) >= length then '截取长度  
  14. txt = left(txt,i)  
  15. exit for  
  16. end if  
  17. next  
  18. GetStringLength=txt  
  19. End Function   

Tags: asp

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2883

 1. 自己写代码产生随机的数字和字母组合,每产生1个去数据库查询该随机码是否已存在,如果已存在,则重新产生,直到不重复为止。

     优点:没发现有啥优点。     

     缺点:产生速度慢,还要查询数据库,当数据量大的时候,可能重复的机率会比较高,要查询多次数据库.

 

2. guid,该方法应该是用的比较多的。     

  优点:使用简单方便,不用自己编写额外的代码     

  缺点:占用数据库空间相对较大,特别是根据guid查询速度比较慢(毕竟是字符串)。

 

3. 主键+随机码的方式,我们产生的随机码保存到数据库肯定会有个主键,用该主键+随机字符来组合。产生步骤:     

  1) 先从id生成器中获取id,比如是155.     

  2)填充成固定位数(比如8位)的字符串(不够位数的左边填0,超过位数直接使用该数字),得到:00000155     

  3)在每个数字后面随机插入1个字母或其它非数字符号,得到:0A0F0R0Y0H1K5L5M

   这样就可以得到1个随机的唯一的邀请码了。    

  优点:使用也比较简单,不用查询数据库。最大的优点是查询的时候,可以根据邀请码直接得到主键id,     

     然后根据id去数据库查询(速度很快),再比较查询出来的邀请码和用户提交的邀请码是否一致。    

  缺点:需要使用id产生器,如果主键是数据库自增长的就不太好用(需要先插入数据库获取id,再更新邀请码)。

 

4. 有时候产品经理说,我要求邀请码都是数字的。把方法3变通下就可以实现唯一的纯数字随机码了。    

  1) 获取id: 155    

  2) 转换成8进制:233    

  3) 转为字符串,并在后面加'9'字符:2339    

  4)在后面随机产生若干个随机数字字符:2003967524987 

   转为8进制后就不会出现9这个字符,然后在后面加个'9',这样就能确定唯一性。最后在后面产生一些随机数字就可以。

      优缺点同方法3

Tags: php

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3122

vb键盘常量

可在代码中的任何地方用下列常数代替实际值:

常数 值 描述

vbKeyLButton 0x1 鼠标左键
vbKeyRButton 0x2 鼠标右键
vbKeyCancel 0x3 CANCEL 键
vbKeyMButton 0x4 鼠标中键
vbKeyBack 0x8 BACKSPACE 键
vbKeyTab 0x9 TAB 键
vbKeyClear 0xC CLEAR 键
vbKeyReturn 0xD ENTER 键
vbKeyShift 0x10 SHIFT 键
vbKeyControl 0x11 CTRL 键
vbKeyMenu 0x12 MENU 键
vbKeyPause 0x13 PAUSE 键
vbKeyCapital 0x14 CAPS LOCK 键
vbKeyEscape 0x1B ESC 键
vbKeySpace 0x20 SPACEBAR 键
vbKeyPageUp 0x21 PAGE UP 键
vbKeyPageDown 0x22 PAGE DOWN 键
vbKeyEnd 0x23 END 键
vbKeyHome 0x24 HOME 键
vbKeyLeft 0x25 LEFT ARROW 键
vbKeyUp 0x26 UP ARROW 键
vbKeyRight 0x27 RIGHT ARROW 键
vbKeyDown 0x28 DOWN ARROW 键
vbKeySelect 0x29 Select 键
vbKeyPrint 0x2A PRINT SCREEN 键
vbKeyExecute 0x2B EXECUTE 键
vbKeySnapshot 0x2C SNAPSHOT 键
vbKeyInsert 0x2D Insert 键
vbKeyDelete 0x2E Delete 键
vbKeyHelp 0x2F HELP 键
vbKeyNumlock 0x90 NUM LOCK 键
A 至 Z 键与 A 杴 Z 字母的 ASCII 码相同:

常数 值 描述
vbKeyA 65 A 键
vbKeyB 66 B 键
vbKeyC 67 C 键
vbKeyD 68 D 键
vbKeyE 69 E 键
vbKeyF 70 F 键
vbKeyG 71 G 键
vbKeyH 72 H 键
vbKeyI 73 I 键
vbKeyJ 74 J 键
vbKeyK 75 K 键
vbKeyL 76 L 键
vbKeyM 77 M 键
vbKeyN 78 N 键
vbKeyO 79 O 键
vbKeyP 80 P 键
vbKeyQ 81 Q 键
vbKeyR 82 R 键
vbKeyS 83 S 键
vbKeyT 84 T 键
vbKeyU 85 U 键
vbKeyV 86 V 键
vbKeyW 87 W 键
vbKeyX 88 X 键
vbKeyY 89 Y 键
vbKeyZ 90 Z 键
0 至 9 键与数字 0 杴 9 的 ASCII 码相同:

查看更多...

Tags: vb

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 3397

Php版的google pr值查询接口

PR(全称PageRank)是Google衡量一个网站的重要标准之一,从而影响Google搜索结果排名。Google官方提供了查询PR的API,如本站PR值:
http://toolbarqueries.google.com.hk/tbr?client=navclient-auto&features=Rank:&q=info:phpddt.com&ch=8fabc62ea
Google PR值查询原理及其简单,只要获取如上接口返回的值处理下就OK了:

PHP代码
  1. <?php  
  2.    
  3. /* 
  4. *功能:对URL进行编码 
  5. *参数说明:$web_url 网站URL,不包含"http://" 
  6. */  
  7. function HashURL($url)  
  8. {     
  9.     $SEED = "Mining PageRank is AGAINST GOOGLE’S TERMS OF SERVICE. Yes, I’m talking to you, scammer.";  
  10.     $Result = 0x01020345;  
  11.     for ($i=0; $i<strlen($url); $i++)   
  12.     {  
  13.         $Result ^= ord($SEED{$i%87}) ^ ord($url{$i});  
  14.         $Result = (($Result >> 23) & 0x1FF) | $Result << 9;  
  15.     }  
  16.     return sprintf("8%x"$Result);  
  17. }  
  18.    
  19. /* 
  20. *功能:根据google提供的pr查询接口获取pagerank 
  21. *参数说明:$domain 网站域名,不包含"http://" 
  22. */  
  23. function pagerank($domain)  
  24. {      
  25.     $StartURL = "http://toolbarqueries.google.com/tbr?client=navclient-auto&features=Rank:&q=info:";  
  26.     $GoogleURL = $StartURL.$domain'&ch='.HashURL($domain);  
  27.     echo $GoogleURL.'<br>';  
  28.     $fcontents = file_get_contents("$GoogleURL");  
  29.     $pagerank = substr($fcontents,9);  
  30.     if (!$pagerankreturn "0";else return $pagerank;  
  31. }  
  32. echo pagerank("phpddt.com");  
  33. ?>  

值得注意的是该接口需要获取一个ch的值,已有HashURL()解决,但是该代码传到服务器Linux 64上出现了int overflow溢出问题,可用如下代码解决:

PHP代码
  1. function trunkbitForce32bit($n) {  
  2.     if (PHP_INT_SIZE <= 4) {  
  3.         settype($n'float');  
  4.         if ($n < 0)  
  5.             $n += 4294967296;  
  6.         return $n;  
  7.     }  
  8.     else   
  9.         {  
  10.         $clearbit = '';  
  11.         for ($i = 0; $i < PHP_INT_SIZE - 4; $i++) {  
  12.             $clearbit .= '00';  
  13.         }  
  14.         for ($i = 0; $i < 4; $i++) {  
  15.             $clearbit .= 'ff';  
  16.         }  
  17.         return ($n & hexdec($clearbit));  
  18.     }  
  19. }  

Tags: php

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 2144

 广告位

↑返回顶部↑