Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > asp函数/类库

asp下IP地址分段计算函数

来源:中文源码网    浏览:207 次    日期:2024-04-26 18:40:49
【下载文档:  asp下IP地址分段计算函数.txt 】


asp下IP地址分段计算函数
IP地址分段计算 在vbs中没有位操作,这样在一个页面中用到了js和vbs,并不好,如果用vbs也可以,不过罗嗦了一些,而且有一点注意,如果在vbs中split("202.102.29.6","."),会得到202,102,29三个数,得不到最后一个6,所以需要将ip换成split("202.102.29.6" & ".",".") 我用vbs做的,由于没有位操作,所以做得比较麻烦 <% function ip2int(ipstr) dim iptemp,max iptemp = split(ipstr&".",".") max = ubound(iptemp) if max <> 4 then exit function end if dim a,b,i a = "&H" for i = 0 to 3 b = Hex(iptemp(i)) if len(b) = 1 then b = "0"&b end if a = a&b next ip2int = CLng(a) end function function int2ip(ip) dim iptemp,a,ipstr,i,length iptemp = Hex(ip) length = 8 - len(iptemp) for i = 1 to length iptemp = "0" & iptemp next a = left(iptemp,2) a = "&H" & a i = CInt(a) a = CStr(i) ipstr = a & "." a = mid(iptemp,3,2) a = "&H" & a i = CInt(a) a = CStr(i) ipstr = ipstr & a & "." a = mid(iptemp,5,2) a = "&H" & a i = CInt(a) a = CStr(i) ipstr = ipstr & a & "." a = right(iptemp,2) a = "&H" & a i = CInt(a) a = CStr(i) ipstr = ipstr & a int2ip = ipstr end function dim testIP,testInt testIP="202.102.29.6" testInt = ip2int(testIP) response.write testIP & " will be encoded to " & testInt & "
" response.write testIP & " will be dencoded to " & int2ip(testInt) & "
" %>

相关内容