动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP实例
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ ASP实例 ]的信息



本月文章推荐
.ASP进阶之文章在线管理更新(4).
.使用JScript.NET创建asp.net页面.
.经典的分页完整程序+注释.
.读取目录下的所有文件(源码).
.用ASPMail组件实现E_mail自动反馈.
.取得服务器上用户组列表的脚本之.
.查看服务器磁盘、文件的aspx..
.发送带附件的HTML格式邮件例程.
.论坛中有新贴子功能的实现.
.取得服务器上用户组列表脚本之VB.
.怎样做自己的二级域名(之二).
.一 些 ASP 小 源 程 序.
.使用w3Sockets组件实现域名查询功.
.词语搭配游戏的制作(ASP)三.
.使用 ASP+ 列表绑定控件(上).
.解密ASP源代码.
.在线实时开通WEB及FTP源程序.
.使用JScript.NET创建asp.net页面.
.使用ASP程序对“HTML炸弹”进行屏.
.实例演练ASP+XML编程(4).

纯ASP(VBscript)写的全球IP地址搜索程序

发表日期:2003-9-30 |


<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
  dim finishgetip,showip,allip
'/////////////////////////////////////////////////////////
'程序还不是很精简,以后再修改
'本程序所用的数据库为-- “冯志宏”-- 所写的--“追捕”--软件中所带IP数据库和
' “国华软件 Guohua Soft”的作者 --“冯国华”—所写的“全球IP地址分配表.chm”合二为一得到的
'感谢“冯志宏”和“冯国华”提供的数据
'数据库中还有不少的重复IP地址,希望有心人能将其删除,减小数据库
'我的程序写的还很笨拙,希望大家能多提意见,多多交流,谢谢!
'///////////////////////////////////////////////////////////
'解决思路: www.knowsky.com
'取得的客户端IP一般是202.11.25.1这种,而数据库中的IP格式为202.011.025.001,这就需要将取得的
'客户端IP转换为与数据库中IP一样的格式
'因为目前我们所用的IP是分为4段,每段3位,中间以“.”分隔
'所以我的思路是将客户端IP以“.”符号分割为4段,即202/11/25/1
'然后再分别核对每一段,如果是3位,则不变;如不足3位,为2位,该段前补1个0,为1,同理,则补2个0
'得到格式化后的IP后,去掉IP的最后一段,即取包括“.”的前11位,与数据库中的startip字段的前11位相比较,查找相同的值
'因为从数据库中可以看到,startip和endip的前三段都是一样的,而最后一段不过是内部子网地址,可以去掉
'所以只要取startip或endip的任意一个字段的前11位与客户端IP的前11位相比较就可以查到正确的所在地
'///////////////////////////////////////////////////////////////
function checkip_trueip()
    '取客户端真实IP
    getclientip = Request.ServerVariables("HTTP_X_FORWARDED_FOR") '如果客户端用了代理服务器,则用Request.ServerVariables("REMOTE_ADDR")方法只能得到空值,则应该用ServerVariables("HTTP_X_FORWARDED_FOR")方法
   If getclientip = "" Then
    getclientip = Request.ServerVariables("REMOTE_ADDR")'如果客户端没用代理,则Request.ServerVariables("HTTP_X_FORWARDED_FOR")得到是空值,应该用Request.ServerVariables("REMOTE_ADDR")方法
   end if
checkip_trueip = getclientip
end function
'/////////////////////////////////////////////////////////
function getaccessrecordset(db,sql,mark,read)'取得Recordset对象
    set conn=getaccessconn(db)'输入参数为db-数据库的相对路径,sql-SQL语句,mark,read为数据库读取方式,1,1为只读,1,3为读写
      'constr="Provider=microsoft.jet.oledb.4.0;"&"data Source="&Server.MapPath(db)
  ' conn.open constr
   set getaccessrecordset=server.CreateObject("ADODB.Recordset")
     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中分隔字符的位置函数
   checkip_locations=Instr(checkstring,".") '将位置的值赋予给函数
end function
'////////////////////////////////////////////////////////////
'以下函数为分割IP,取得每次分割后“.”符号右边的IP剩余的字符串
function checkip_left(checkstring)
    locations_left=checkip_locations(checkstring) '得到在IP剩余的字符串中“.”第一次出现的位置
   iplength_left=Len(checkstring) '取得IP剩余的字符串的长度
   divide_locations_left=iplength_left-locations_left '取得在IP剩余的字符串中“.”第一次出现的位置,从右往左数是多少位
    ipstr_left=Right(checkstring,divide_locations_left) '取得本次分割后,“.”符号右边的IP剩余的字符串
  checkip_left=ipstr_left  '将上面得到的字符串赋给函数
end function
'///////////////////////////////////////////////////////////
'以下函数为分割IP,取得每次分割后“.”符号左边的IP字符串,即将IP分为四段,每一段的字符串

function checkip_right(checkstring)
    locations_right=checkip_locations(checkstring) '取得在IP中“.”第一次出现的位置
   iplength_right=Len(checkstring)  '取得IP字符串长度
   divide_locations_right=iplength_right-locations_right '取得在IP剩余的字符串中“.”第一次出现的位置,从右往左数是多少位
   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是否为内部网IP
'我写的判断是以:127.0.0.0-127.XXX.XXX.255和192.0.0.0-192.XXX.XXX.255为依据,如果为这二者,则是内部网IP,反之为外部网
'判断内部IP的依据是什么,我也不清楚,所以这里要高手多多指点,并加以修正,与我联系 
function checkiplocal(checkstring)
  dim re1
  set re1=new RegExp '取得正则表达式对象
    're1.pattern中的表达式为,内部网的IP应为127或192开头,中间为0-9中任意1-3个数字加"."组成一段
  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 '"."字符出现的位置
     iplength=Len(checksting)
     locations=Instr(checkstring,".") '从左到右检索“.”符号在IP字符串中第一次出现的位置
  '以“.”字符将IP分割为4段
  locations2=iplength-locations
  ipstring1=Left(checkstring,locations)
  ipstring2=Right(checkstring,locations2)
end function
'/////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////
ipinfo_local="您的IP是内部网IP!"
  ipinfo_remote="外部网IP!"
   getip=checkip_trueip()
    currentip=checkiplocal(getip) '调用checkiplocal()函数对得到的IP进行检查,确定是内部网地址还是外部网地址
      'if currentip=true then'测试代码
   'response.Write(ipinfo_local)
   if currentip=true then  '为假
      response.Write(ipinfo_local)'说明为内部网IP
     else
    '进行转换
    '以下为循环提取并按位补0将IP分为4段
   locations=checkip_locations(getip)'取得“.”在第一次分割前在IP中第一次出现的位置
   iplength=Len(getip) '取得客户端IP的长度
   divide_locations=iplength-locations '取得将客户端IP从右向左数到IP从左往右数第一个“.”的位置   
     ipstr1=Trim(Replace(Left(getip,locations),".",""))
  ipstr2=Right(getip,divide_locations)'取得第一次分割后客户端右边剩下的数值
  '如果IP分为4段后每一段不足3位则补0
  if Len(ipstr1)="2" then ipstr1="0"&ipstr1 '长度为二,不足三位,在字符串之前补一个0
  if Len(ipstr1)="3" then ipstr1=ipstr1 '据上类推
  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的第四段进行补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="未知地区" '国家或省份
  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地址有错误,请与我联系,或下载数据库更正,谢谢!<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语法,正则表达式&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是未知,如果你愿意,请提交你的所在地:</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%">具体所在地或是什么网的用户:</td>
            <td width="44%">
              <input type="text" name="areauser">
            </td>
            <td width="35%">例如:北京清华大学或北京网通用户</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.knowsky.com/ip

上一篇:Jmail发信的实例,模块化随时调用 人气:22850
下一篇:用XML+FSO+JS实现服务器端文件的选择 人气:14496
浏览全部IP的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-7-24 Sablog-X v2.0 预览版
2008-7-24 帝国备份王EmpireBak 2008 正式版
2008-7-24 网趣网上购物系统时尚版 v8.2
2008-7-24 纵横B2B电子商务系统XYECS!B2B v
2008-7-24 e路小说小偷 v1.2.0723
2008-7-24 凌风美女图片站程序 v2.2
2008-7-24 TOM15电影收索程序
2008-7-24 清风信息自动采集生成系统 v1.0
2008-7-24 QQ邮箱编辑器 v1.0 (小小菜刀ASP
2008-7-19 UltraEdit 简体中文增强版 14.10
2008-7-19 CentOS 5.2 i386 LiveCD
2008-7-19 Snapture多功能相机 v1.4
2008-7-19 iAcces中文输入法 v1.0Build016
2008-7-19 Cookbook烹饪秘籍 v2.5
2008-7-19 苹果专用DVD转换工具 v1.1.59汉化
2008-7-19 Modem修复软件ZiPhone修改版04.0
2008-7-19 AgileMessenger即时通讯工具美化
2008-7-19 Sketches画图软件 v0.7b6破解版


  发表评论
姓 名: 验证码:
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号
ホームページ制作 不動産検索システム 求人情報
防水工事·改修工事 フットサル大会 探偵