<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
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
'我写的判断是以:1***0.0.0-127.XXX.XXX.255和19***.0.0-192.XXX.XXX.255为依据,如果为这二者,则是内部网IP,反之为外部网
'判断内部IP的依据是什么,我也不清楚,所以这里要高手多多指点,并加以修正,与我联系
function checkiplocal(checkstring)
dim re1
set re1=new RegExp '取得正则表达式对象
're***attern中的表达式为,内部网的IP应为127或192开头,中间为0-9中任意1-3个数字加"."组成一段
re***attern="^(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})$"
re***lobal=false
re***gnorecase=false
ch***iplocal=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'测试代码
're***nse.Write(ipinfo_local)
if currentip=true then '为假
re***nse.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
're***nse.write ipstr1&"
" '写出IP分割后的每段的值
're***nse.write ipstr12&"
"
're***nse.write ipstr13&"
"
're***nse.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("#w***dip.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
're***nse.write("您的IP是:"&showip&" ")
're***nse.write("您来自:"&ipaddr&" ")
're***nse.write("您是:"&iplocal)
rs.close
set rs=nothing
%>
<%="您的IP是:"&showip&" "%>
<%="您来自:"&ipaddr&" "%>
<%="您是:"&iplocal&"
"%>
如果IP地址有错误,请与我联系,或下载数据库更正,谢谢!
Sc***t56.rar">下载Sc***t56.CHM-->1.34M | 简介:Microsoft的帮助文档,有VBscript语法,JScript语法,正则表达式 | ||
ip***rch.rar">下载ASP全球IP地址搜索程序 | ASP+ACCESS 大小401K;格式rar | ||
如果你的IP是未知,如果你愿意,请提交你的所在地: |
下一篇: Jmail发信的实例,模块化随时调用