{"id":764,"date":"2011-11-18T00:01:41","date_gmt":"2011-11-17T16:01:41","guid":{"rendered":""},"modified":"2014-03-11T22:40:02","modified_gmt":"2014-03-11T14:40:02","slug":"asp%e5%a6%82%e4%bd%95%e8%b0%83%e7%94%a8ip%e5%ba%93","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2011\/11\/18\/764.htm","title":{"rendered":"ASP\u5982\u4f55\u8c03\u7528IP\u5e93"},"content":{"rendered":"<p>&lt;%<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u8fd4\u56deIP\u4fe1\u606f Disp_IPAddressData(IP,0)<br \/>\n&#8216; ============================================<br \/>\nFunction Look_Ip(IP)<br \/>\nDim Wry, IPType, QQWryVersion, IpCounter<br \/>\n&#8216; \u8bbe\u7f6e\u7c7b\u5bf9\u8c61<br \/>\nSet Wry = New TQQWry<br \/>\n&#8216; \u5f00\u59cb\u641c\u7d22\uff0c\u5e76\u8fd4\u56de\u641c\u7d22\u7ed3\u679c<br \/>\n&#8216; \u60a8\u53ef\u4ee5\u6839\u636e QQWry(IP) \u8fd4\u56de\u503c\u6765\u5224\u65ad\u8be5IP\u5730\u5740\u5728\u6570\u636e\u5e93\u4e2d\u662f\u5426\u5b58\u5728\uff0c\u5982\u679c\u4e0d\u5b58\u5728\u53ef\u4ee5\u6267\u884c\u5176\u4ed6\u7684\u4e00\u4e9b\u64cd\u4f5c<br \/>\n&#8216; \u6bd4\u5982\u60a8\u81ea\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u4f5c\u4e3a\u8ffd\u6355\u7b49\uff0c\u8fd9\u91cc\u6211\u5c31\u4e0d\u8be6\u7ec6\u8bf4\u660e\u4e86<br \/>\nIPType = Wry.QQWry(IP)<br \/>\n&#8216; Country\uff1a\u56fd\u5bb6\u5730\u533a\u5b57\u6bb5<br \/>\n&#8216; LocalStr\uff1a\u7701\u5e02\u53ca\u5176\u4ed6\u4fe1\u606f\u5b57\u6bb5<br \/>\nLook_Ip =Wry.Country &amp; &quot;&quot; &amp; Wry.LocalStr<br \/>\n&#8221;&#8221;&#8217;Look_Ip = Wry.Country &amp; &quot;&quot;<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u8fd4\u56deIP\u4fe1\u606f JS\u8c03\u7528<br \/>\n&#8216; ============================================<br \/>\nFunction Disp_IPAddressData(IP, sType)<br \/>\nDim Wry, IPType<br \/>\nSet Wry = New TQQWry<br \/>\nIPType = Wry.QQWry(IP)<\/p>\n<p>Select Case sType<br \/>\nCase 1 Disp_IPAddressData = IP<br \/>\nCase 2 Disp_IPAddressData = Wry.Country<br \/>\nCase 3 Disp_IPAddressData = Wry.LocalStr<br \/>\n&#8216;Case Else Disp_IPAddressData = Wry.Country &amp; &quot;&quot; &amp; Wry.LocalStr<br \/>\nCase Else Disp_IPAddressData = Wry.Country <br \/>\nEnd Select<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u8fd4\u56deQQWry\u4fe1\u606f<br \/>\n&#8216; ============================================<br \/>\nFunction WryInfo()<br \/>\nDim Wry, IPType, QQWry_tem(0), QQWry_tem1(1)<br \/>\n&#8216; \u8bbe\u7f6e\u7c7b\u5bf9\u8c61<br \/>\nSet Wry = New TQQWry<br \/>\nIPType = Wry.QQWry(&quot;255.255.255.254&quot;)<br \/>\n&#8216; \u8bfb\u53d6\u6570\u636e\u5e93\u7248\u672c\u4fe1\u606f<br \/>\nQQWry_tem(0) = Wry.Country &amp; &quot; &quot; &amp; Wry.LocalStr<br \/>\n&#8216; \u8bfb\u53d6\u6570\u636e\u5e93IP\u5730\u5740\u6570\u76ee<br \/>\nQQWry_tem1(1) = Wry.RecordCount + 1<br \/>\nWryInfo = QQWry_tem(0)&amp; &quot; &quot; &amp; QQWry_tem1(1)<br \/>\nEnd Function<\/p>\n<p>Class TQQWry<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u53d8\u91cf\u58f0\u540d<br \/>\n&#8216; ============================================<br \/>\nDim Country, LocalStr, Buf, OffSet<br \/>\nPrivate StartIP, EndIP, CountryFlag<br \/>\nPublic QQWryFile<br \/>\nPublic FirstStartIP, LastStartIP, RecordCount<br \/>\nPrivate Stream, EndIPOff<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u7c7b\u6a21\u5757\u521d\u59cb\u5316<br \/>\n&#8216; ============================================<br \/>\nPrivate Sub Class_Initialize<br \/>\nCountry = &quot;&quot;<br \/>\nLocalStr = &quot;&quot;<br \/>\nStartIP = 0<br \/>\nEndIP = 0<br \/>\nCountryFlag = 0 <br \/>\nFirstStartIP = 0 <br \/>\nLastStartIP = 0 <br \/>\nEndIPOff = 0 <br \/>\nQQWryFile = Server.MapPath(&quot;\/DATA\/QQWry.dat&quot;) &#8216;QQ\u7eaf\u771fIP\u5e93\u5b58\u653e\u8def\u5f84\uff0c\u8981\u6539\u4e3a\u4f60\u7684\u8def\u5f84<br \/>\nEnd Sub<br \/>\n&#8216; ============================================<br \/>\n&#8216; IP\u5730\u5740\u8f6c\u6362\u6210\u6574\u6570<br \/>\n&#8216; ============================================<br \/>\nFunction IPToInt(IP)<br \/>\nDim IPArray, i<br \/>\nIPArray = Split(IP, &quot;.&quot;, -1)<br \/>\nFOr i = 0 to 3<br \/>\nIf Not IsNumeric(IPArray(i)) Then IPArray(i) = 0<br \/>\nIf CInt(IPArray(i)) &lt; 0 Then IPArray(i) = Abs(CInt(IPArray(i)))<br \/>\nIf CInt(IPArray(i)) &gt; 255 Then IPArray(i) = 255<br \/>\nNext<br \/>\nIPToInt = (CInt(IPArray(0))*256*256*256) + (CInt(IPArray(1))*256*256) + (CInt(IPArray(2))*256) + CInt(IPArray(3))<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u6574\u6570\u9006\u8f6cIP\u5730\u5740<br \/>\n&#8216; ============================================<br \/>\nFunction IntToIP(IntValue)<br \/>\np4 = IntValue &#8211; Fix(IntValue\/256)*256<br \/>\nIntValue = (IntValue-p4)\/256<br \/>\np3 = IntValue &#8211; Fix(IntValue\/256)*256<br \/>\nIntValue = (IntValue-p3)\/256<br \/>\np2 = IntValue &#8211; Fix(IntValue\/256)*256<br \/>\nIntValue = (IntValue &#8211; p2)\/256<br \/>\np1 = IntValue<br \/>\nIntToIP = Cstr(p1) &amp; &quot;.&quot; &amp; Cstr(p2) &amp; &quot;.&quot; &amp; Cstr(p3) &amp; &quot;.&quot; &amp; Cstr(p4)<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u83b7\u53d6\u5f00\u59cbIP\u4f4d\u7f6e<br \/>\n&#8216; ============================================<br \/>\nPrivate Function GetStartIP(RecNo)<br \/>\nOffSet = FirstStartIP + RecNo * 7<br \/>\nStream.Position = OffSet<br \/>\nBuf = Stream.Read(7)<\/p>\n<p>EndIPOff = AscB(MidB(Buf, 5, 1)) + (AscB(MidB(Buf, 6, 1))*256) + (AscB(MidB(Buf, 7, 1))*256*256) <br \/>\nStartIP = 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)<br \/>\nGetStartIP = StartIP<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u83b7\u53d6\u7ed3\u675fIP\u4f4d\u7f6e<br \/>\n&#8216; ============================================<br \/>\nPrivate Function GetEndIP()<br \/>\nStream.Position = EndIPOff<br \/>\nBuf = Stream.Read(5)<br \/>\nEndIP = 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) <br \/>\nCountryFlag = AscB(MidB(Buf, 5, 1))<br \/>\nGetEndIP = EndIP<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u83b7\u53d6\u5730\u57df\u4fe1\u606f\uff0c\u5305\u542b\u56fd\u5bb6\u548c\u548c\u7701\u5e02<br \/>\n&#8216; ============================================<br \/>\nPrivate Sub GetCountry(IP)<br \/>\nIf (CountryFlag = 1 Or CountryFlag = 2) Then<br \/>\nCountry = GetFlagStr(EndIPOff + 4)<br \/>\nIf CountryFlag = 1 Then<br \/>\nLocalStr = GetFlagStr(Stream.Position)<br \/>\n&#8216; \u4ee5\u4e0b\u7528\u6765\u83b7\u53d6\u6570\u636e\u5e93\u7248\u672c\u4fe1\u606f<br \/>\nIf IP &gt;= IPToInt(&quot;255.255.255.0&quot;) And IP &lt;= IPToInt(&quot;255.255.255.255&quot;) Then<br \/>\nLocalStr = GetFlagStr(EndIPOff + 21)<br \/>\nCountry = GetFlagStr(EndIPOff + 12)<br \/>\nEnd If<br \/>\nElse<br \/>\nLocalStr = GetFlagStr(EndIPOff + 8)<br \/>\nEnd If<br \/>\nElse<br \/>\nCountry = GetFlagStr(EndIPOff + 4)<br \/>\nLocalStr = GetFlagStr(Stream.Position)<br \/>\nEnd If<br \/>\n&#8216; \u8fc7\u6ee4\u6570\u636e\u5e93\u4e2d\u7684\u65e0\u7528\u4fe1\u606f<br \/>\nCountry = Trim(Country)<br \/>\nLocalStr = Trim(LocalStr)<br \/>\nIf InStr(Country, &quot;CZ88.NET&quot;) Then Country = &quot;&quot;<br \/>\nIf InStr(LocalStr, &quot;CZ88.NET&quot;) Then LocalStr = &quot;&quot;<br \/>\nEnd Sub<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u83b7\u53d6IP\u5730\u5740\u6807\u8bc6\u7b26<br \/>\n&#8216; ============================================<br \/>\nPrivate Function GetFlagStr(OffSet)<br \/>\nDim Flag<br \/>\nFlag = 0<br \/>\nDo While (True)<br \/>\nStream.Position = OffSet<br \/>\nFlag = AscB(Stream.Read(1))<br \/>\nIf(Flag = 1 Or Flag = 2 ) Then<br \/>\nBuf = Stream.Read(3) <br \/>\nIf (Flag = 2 ) Then<br \/>\nCountryFlag = 2<br \/>\nEndIPOff = OffSet &#8211; 4<br \/>\nEnd If<br \/>\nOffSet = AscB(MidB(Buf, 1, 1)) + (AscB(MidB(Buf, 2, 1))*256) + (AscB(MidB(Buf, 3, 1))*256*256)<br \/>\nElse<br \/>\nExit Do<br \/>\nEnd If<br \/>\nLoop<\/p>\n<p>If (OffSet &lt; 12 ) Then<br \/>\nGetFlagStr = &quot;&quot;<br \/>\nElse<br \/>\nStream.Position = OffSet<br \/>\nGetFlagStr = GetStr() <br \/>\nEnd If<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u83b7\u53d6\u5b57\u4e32\u4fe1\u606f<br \/>\n&#8216; ============================================<br \/>\nPrivate Function GetStr() <br \/>\nDim c<br \/>\nGetStr = &quot;&quot;<br \/>\nDo While (True)<br \/>\nc = AscB(Stream.Read(1))<br \/>\nIf (c = 0) Then Exit Do<\/p>\n<p>&#8216;\u5982\u679c\u662f\u53cc\u5b57\u8282\uff0c\u5c31\u8fdb\u884c\u9ad8\u5b57\u8282\u5728\u7ed3\u5408\u4f4e\u5b57\u8282\u5408\u6210\u4e00\u4e2a\u5b57\u7b26<br \/>\nIf c &gt; 127 Then<br \/>\nIf Stream.EOS Then Exit Do<br \/>\nGetStr = GetStr &amp; Chr(AscW(ChrB(AscB(Stream.Read(1))) &amp; ChrB(C)))<br \/>\nElse<br \/>\nGetStr = GetStr &amp; Chr(c)<br \/>\nEnd If<br \/>\nLoop <br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u6838\u5fc3\u51fd\u6570\uff0c\u6267\u884cIP\u641c\u7d22<br \/>\n&#8216; ============================================<br \/>\nPublic Function QQWry(DotIP)<br \/>\nDim IP, nRet<br \/>\nDim RangB, RangE, RecNo<\/p>\n<p>IP = IPToInt (DotIP)<\/p>\n<p>Set Stream = CreateObject(&quot;ADodb.Stream&quot;)<br \/>\nStream.Mode = 3<br \/>\nStream.Type = 1<br \/>\nStream.Open<br \/>\nStream.LoadFromFile QQWryFile<br \/>\nStream.Position = 0<br \/>\nBuf = Stream.Read(8)<\/p>\n<p>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)<br \/>\nLastStartIP = 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)<br \/>\nRecordCount = Int((LastStartIP &#8211; FirstStartIP)\/7)<br \/>\n&#8216; \u5728\u6570\u636e\u5e93\u4e2d\u627e\u4e0d\u5230\u4efb\u4f55IP\u5730\u5740<br \/>\nIf (RecordCount &lt;= 1) Then<br \/>\nCountry = &quot;\u672a\u77e5&quot;<br \/>\nQQWry = 2<br \/>\nExit Function<br \/>\nEnd If<\/p>\n<p>RangB = 0<br \/>\nRangE = RecordCount<\/p>\n<p>Do While (RangB &lt; (RangE &#8211; 1)) <br \/>\nRecNo = Int((RangB + RangE)\/2) <br \/>\nCall GetStartIP (RecNo)<br \/>\nIf (IP = StartIP) Then<br \/>\nRangB = RecNo<br \/>\nExit Do<br \/>\nEnd If<br \/>\nIf (IP &gt; StartIP) Then<br \/>\nRangB = RecNo<br \/>\nElse <br \/>\nRangE = RecNo<br \/>\nEnd If<br \/>\nLoop<\/p>\n<p>Call GetStartIP(RangB)<br \/>\nCall GetEndIP()<\/p>\n<p>If (StartIP &lt;= IP) And ( EndIP &gt;= IP) Then<br \/>\n&#8216; \u6ca1\u6709\u627e\u5230<br \/>\nnRet = 0<br \/>\nElse<br \/>\n&#8216; \u6b63\u5e38<br \/>\nnRet = 3<br \/>\nEnd If<br \/>\nCall GetCountry(IP)<\/p>\n<p>QQWry = nRet<br \/>\nEnd Function<br \/>\n&#8216; ============================================<br \/>\n&#8216; \u7c7b\u7ec8\u7ed3<br \/>\n&#8216; ============================================<br \/>\nPrivate Sub Class_Terminate<br \/>\nOn ErrOr Resume Next<br \/>\nStream.Close<br \/>\nIf Err Then Err.Clear<br \/>\nSet Stream = Nothing<br \/>\nEnd Sub<br \/>\nEnd Class <br \/>\n%&gt;<br \/>\n&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;% &#8216; ============================================ &#8216; \u8fd4\u56deIP\u4fe1\u606f Disp_IPAddressData(IP,0) &#8216; =============&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-764","post","type-post","status-publish","format-standard","hentry","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/764","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=764"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/764\/revisions"}],"predecessor-version":[{"id":66597,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/764\/revisions\/66597"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=764"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=764"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}