国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學(xué)院 > 開發(fā)設(shè)計 > 正文

純ASP(VBscript)寫的全球IP地址搜索程序

2019-11-18 19:56:32
字體:
供稿:網(wǎng)友

<%@LANGUAGE="VBSCR<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
  dim finishgetip,showip,allip
'/////////////////////////////////////////////////////////
'程序還不是很精簡,以后再修改
'本程序所用的
數(shù)據(jù)庫為-- “馮志宏”-- 所寫的--“追捕”--軟件中所帶IP數(shù)據(jù)庫和
' “國華軟件 Guohua Soft”的作者 --“馮國華”—所寫的“全球IP地址分配表.chm”合二為一得到的
'感謝“馮志宏”和“馮國華”提供的數(shù)據(jù)
'數(shù)據(jù)庫中還有不少的重復(fù)IP地址,希望有心人能將其刪除,減小數(shù)據(jù)庫
'我的程序?qū)懙倪€很笨拙,希望大家能多提意見,多多交流,謝謝!
'///////////////////////////////////////////////////////////
'解決思路: www.survivalescaperooms.com
'取得的客戶端IP一般是202.11.25.1這種,而數(shù)據(jù)庫中的IP格式為202.011.025.001,這就需要將取得的
'客戶端IP轉(zhuǎn)換為與數(shù)據(jù)庫中IP一樣的格式
'因為目前我們所用的IP是分為4段,每段3位,中間以“.”分隔
'所以我的思路是將客戶端IP以“.”符號分割為4段,即202/11/25/1
'然后再分別核對每一段,如果是3位,則不變;如不足3位,為2位,該段前補1個0,為1,同理,則補2個0
'得到格式化后的IP后,去掉IP的最后一段,即取包括“.”的前11位,與數(shù)據(jù)庫中的startip字段的前11位相比較,查找相同的值
'因為從數(shù)據(jù)庫中可以看到,startip和endip的前三段都是一樣的,而最后一段不過是內(nèi)部子網(wǎng)地址,可以去掉
'所以只要取startip或endip的任意一個字段的前11位與客戶端IP的前11位相比較就可以查到正確的所在地
'///////////////////////////////////////////////////////////////
function checkip_trueip()
    '取客戶端真實IP
    getclientip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") '如果客戶端用了代理服務(wù)器,則用Request.ServerVariables("REMOTE_ADDR")方法只能得到空值,則應(yīng)該用ServerVariables("HTTP_X_FORWARDED_FOR")方法
   If getclientip = "" Then
    getclientip = Request.ServerVariables("REMOTE_ADDR")'如果客戶端沒用代理,則Request.ServerVariables("HTTP_X_FORWARDED_FOR")得到是空值,應(yīng)該用Request.ServerVariables("REMOTE_ADDR")方法
   end if
checkip_trueip = getclientip
end function
'/////////////////////////////////////////////////////////
function getaccessrecordset(db,sql,mark,read)'取得Recordset對象
    set conn=getaccessconn(db)'輸入?yún)?shù)為db-數(shù)據(jù)庫的相對路徑,sql-SQL語句,mark,read為數(shù)據(jù)庫讀取方式,1,1為只讀,1,3為讀寫
      'constr="     getaccessrecordset.open sql,conn,mark,read
         End function
'////////////////////////////////////////////////////////////
function getaccessconn(db)'取得connection對象
set getaccessconn=server.CreateObject("ADODB.Connection")
 'constr="DRIVER={MICROSOFT ACCESS DRIVER (*.MDB)};DBQ="&SERVER.MAPPATH("allcon/#bbsall.mdb")
 constr="Provider=microsoft.jet.oledb.4.0;"&"data Source="&Server.MapPath(db)
 getaccessconn.open constr
  end function
'////////////////////////////////////////////////////////////
dim getip
'getip=(trim(request.ServerVariables("REMOTE_ADDR")))'從客戶端獲取IP
'getip=(trim(request.QueryString("comes"))) '自己輸入IP測試
'response.Write(getip&"<br>")
'////////////////////////////////////////////////////////////
function checkip_locations(checkstring) '返回IP中分隔字符的位置函數(shù)
   checkip_locations=Instr(checkstring,".") '將位置的值賦予給函數(shù)
end function
'////////////////////////////////////////////////////////////
'以下函數(shù)為分割I(lǐng)P,取得每次分割后“.”符號右邊的IP剩余的字符串
function checkip_left(checkstring)
    locations_left=checkip_locations(checkstring) '得到在IP剩余的字符串中“.”第一次出現(xiàn)的位置
   iplength_left=Len(checkstring) '取得IP剩余的字符串的長度
   divide_locations_left=iplength_left-locations_left '取得在IP剩余的字符串中“.”第一次出現(xiàn)的位置,從右往左數(shù)是多少位
    ipstr_left=Right(checkstring,divide_locations_left) '取得本次分割后,“.”符號右邊的IP剩余的字符串
  checkip_left=ipstr_left  '將上面得到的字符串賦給函數(shù)
end function
'///////////////////////////////////////////////////////////
'以下函數(shù)為分割I(lǐng)P,取得每次分割后“.”符號左邊的IP字符串,即將IP分為四段,每一段的字符串

function checkip_right(checkstring)
    locations_right=checkip_locations(checkstring) '取得在IP中“.”第一次出現(xiàn)的位置
   iplength_right=Len(checkstring)  '取得IP字符串長度
   divide_locations_right=iplength_right-locations_right '取得在IP剩余的字符串中“.”第一次出現(xiàn)的位置,從右往左數(shù)是多少位
   ipstr11=Trim(Replace(Left(checkstring,locations_right),".","")) '將得到的“.”左邊的字符串去掉"."符號
   '如果IP分為4段后每一段不足3位則補0
  if Len(ipstr11)="2" then ipstr11="0"&ipstr11
  if Len(ipstr11)="3" then ipstr11=ipstr11
  if Len(ipstr11)="1" then ipstr11="00"&ipstr11
  checkip_right=ipstr11 '得到“.”符號之前的字符串,即本次分割后得到的IP分割為四段后其中的一段
end function

'/////////////////////////////////////////////////////////
'檢查IP是否為內(nèi)部網(wǎng)IP
'我寫的判斷是以:127.0.0.0-127.XXX.XXX.255和192.0.0.0-192.XXX.XXX.255為依據(jù),如果為這二者,則是內(nèi)部網(wǎng)IP,反之為外部網(wǎng)
'判斷內(nèi)部IP的依據(jù)是什么,我也不清楚,所以這里要高手多多指點,并加以修正,與我聯(lián)系 
function checkiplocal(checkstring)
  dim re1
  set re1=new RegExp '取得正則表達(dá)式對象
    're1.pattern中的表達(dá)式為,內(nèi)部網(wǎng)的IP應(yīng)為127或192開頭,中間為0-9中任意1-3個數(shù)字加"."組成一段
  re1.pattern="^(127/.[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3})|(192/.[0-9]{1,3}/.[0-9]{1,3}/.[0-9]{1,3})$"
  re1.global=false
  re1.Ignorecase=false
  checkiplocal=re1.test(checkstring)
  set re1=nothing
end function
'//////////////////////////////////////////////////////////////////////
function checkip_remote(checkstring)
   dim iplength 'IP字符串的長度
   dim locations '"."字符出現(xiàn)的位置
     iplength=Len(checksting)
     locations=Instr(checkstring,".") '從左到右檢索“.”符號在IP字符串中第一次出現(xiàn)的位置
  '以“.”字符將IP分割為4段
  locations2=iplength-locations
  ipstring1=Left(checkstring,locations)
  ipstring2=Right(checkstring,locations2)
end function
'/////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////
ipinfo_local="您的IP是內(nèi)部網(wǎng)IP!"
  ipinfo_remote="外部網(wǎng)IP!"
   getip=checkip_trueip()
    currentip=checkiplocal(getip) '調(diào)用checkiplocal()函數(shù)對得到的IP進(jìn)行檢查,確定是內(nèi)部網(wǎng)地址還是外部網(wǎng)地址
      'if currentip=true then'測試代碼
   'response.Write(ipinfo_local)
   if currentip=true then  '為假
      response.Write(ipinfo_local)'說明為內(nèi)部網(wǎng)IP
     else
    '進(jìn)行轉(zhuǎn)換
    '以下為循環(huán)提取并按位補0將IP分為4段
   locations=checkip_locations(getip)'取得“.”在第一次分割前在IP中第一次出現(xiàn)的位置
   iplength=Len(getip) '取得客戶端IP的長度
   divide_locations=iplength-locations '取得將客戶端IP從右向左數(shù)到IP從左往右數(shù)第一個“.”的位置   
     ipstr1=Trim(Replace(Left(getip,locations),".",""))
  ipstr2=Right(getip,divide_locations)'取得第一次分割后客戶端右邊剩下的數(shù)值
  '如果IP分為4段后每一段不足3位則補0
  if Len(ipstr1)="2" then ipstr1="0"&ipstr1 '長度為二,不足三位,在字符串之前補一個0
  if Len(ipstr1)="3" then ipstr1=ipstr1 '據(jù)上類推
  if Len(ipstr1)="1" then ipstr1="00"&ipstr1  '這時的ipstr1為IP的第一段
 
  ipstr12=checkip_right(ipstr2)  '這時的ipstr12為IP的第二段
  ipstr122=checkip_left(ipstr2)
  ipstr13=checkip_right(ipstr122) '這時的ipstr13為IP的第三段
  ipstr14=checkip_left(ipstr122) '這時的ipstr14為IP的第四段
  if Len(ipstr14)="1" then ipstr14="00"&ipstr14 '對得到的IP的第四段進(jìn)行補0,此步驟可不要
  if Len(ipstr14)="2" then ipstr14="0"&ipstr14
  if Len(ipstr14)="3" then ipstr14=ipstr14
 
  'response.write ipstr1&"<br>"  '寫出IP分割后的每段的值
  'response.write ipstr12&"<br>"
  'response.write ipstr13&"<br>"
  'response.write ipstr14
    allip=ipstr1&"."&ipstr12&"."&ipstr13&"."&ipstr14
  finishgetip=left(allip,11)
    dim ipaddr,iplocal,sqls
 '以下SQL語句為提取startip字段左邊11位值是否等于客戶端IP的左邊的11位的值
 sqls="SELECT country_state,areauser FROM ip WHERE Left(startip,11)='"&finishgetip&"'"
  set rs=getaccessrecordset("#worldip.mdb",sqls,"1","1") '得到查詢值
 if rs.eof then  '如果沒找到與客戶端IP相等的值
     showip=checkip_trueip() '把客戶端IP賦予showip
  ipaddr="未知地區(qū)" '國家或省份
  iplocal="未知地點" '具體的地方
   else
      showip=checkip_trueip()
      ipaddr=rs("country_state")
         iplocal=rs("areauser")
 end if
   'response.write("您的IP是:"&showip&"&nbsp;")
   'response.write("您來自:"&ipaddr&"&nbsp;")
   'response.write("您是:"&iplocal)
   rs.close
     set rs=nothing
  %>
   <%="您的IP是:"&showip&"&nbsp;"%>
   <%="您來自:"&ipaddr&"&nbsp;"%>
   <%="您是:"&iplocal&"<br>"%>
 
如果IP地址有錯誤,請與我聯(lián)系,或下載數(shù)據(jù)庫更正,謝謝!<br>
<table width="760" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="203"><a href="Script56.rar">下載Script56.CHM</a>--&gt;1.34M</td>
    <td width="548">簡介:Microsoft的幫助文檔,有VBscript語法,JScript語法,正則表達(dá)式&nbsp;&nbsp;</td>
    <td width="3">&nbsp;</td>
    <td width="6">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><a href="ipsearch.rar">下載
asp全球IP地址搜索程序</a></td>
    <td>ASP+ACCESS&nbsp;&nbsp;&nbsp;&nbsp;大小401K;格式rar</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><font color="#000099">&nbsp;</font>&nbsp;<font color="#0000FF">&nbsp;</font></td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>如果你的IP是未知,如果你愿意,請?zhí)峤荒愕乃诘兀?lt;/td>
    <td>
      <form name="form1" method="post" action="postip.asp">
        <table width="100%" border="1" cellspacing="0" cellpadding="0">
          <tr>
            <td width="21%"> 省份: </td>
            <td width="44%">
              <input type="text" name="country_state">
            </td>
            <td width="35%">&nbsp;</td>
          </tr>
          <tr>
            <td width="21%">具體所在地或是什么網(wǎng)的用戶:</td>
            <td width="44%">
              <input type="text" name="areauser">
            </td>
            <td width="35%">例如:北京清華大學(xué)或北京網(wǎng)通用戶</td>
          </tr>
          <tr>
            <td width="21%">&nbsp;</td>
            <td width="44%">
              <input type="hidden" name="startip" value="<%=finishgetip&".000"%>">
              <input type="hidden" name="endip" value="<%=finishgetip&".255"%>">
            </td>
            <td width="35%">&nbsp;</td>
          </tr>
          <tr>
            <td width="21%">&nbsp;</td>
            <td width="44%">
              <input type="submit" name="Submit" value="提交">
            </td>
            <td width="35%">&nbsp;</td>
          </tr>
        </table>
      </form>
    </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
  <%
  end if
  %>
</body>
</html>

演示地址:http://www.survivalescaperooms.com/ip


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 汝城县| 广南县| 基隆市| 手游| 盐边县| 揭阳市| 安阳县| 扎兰屯市| 昌吉市| 黄浦区| 栾川县| 舒城县| 灌云县| 昌江| 博罗县| 汝城县| 昌黎县| 弥渡县| 武强县| 金秀| 苏州市| 钟祥市| 印江| 罗田县| 贵州省| 石柱| 伽师县| 习水县| 南投县| 东光县| 孝感市| 南丹县| 通海县| 吉林省| 九寨沟县| 天柱县| 古交市| 濉溪县| 永修县| 五华县| 栖霞市|