IP address segmentation calculation
<scriptlanguage="JScript"Runat="Server">
functionIPDeCode(EIP){
varIp1,Ip2,Ip3,Ip4;
Ip1=moveByteR(EIP&0xff000000,3);
Ip2=moveByteR(EIP&0x00ff0000,2);
Ip3=moveByteR(EIP&0x0000ff00,1);
Ip4=EIP&0x000000ff;
returnIp1+"."+Ip2+"."+Ip3+"."+Ip4;
}
functionmoveByteL(num,bytenum){
returnnum<<=(bytenum*8)
}
functionmoveByteR(num,bytenum){
returnnum>>>=(bytenum*8)
}
</script>
There is no bit operation in vbs, so it is not good to use js and vbs in a page. It is also OK if you use vbs, but it is a bit verbose. And one thing is a little bit noticeable. If you split("202.102.29.6",".") in vbs, you will get three numbers 202, 102, and 29, and you will not get the last 6, so you need to change ip to split("202.102.29.6"&".",".")
I did it with vbs, and since there is no bit operation, it is more troublesome
<%
functionip2int(ipstr)
dimiptemp,max
iptemp=split(ipstr&".",".")
max=ubund(iptemp)
ifmax<>4then
exitfunction
endif
dima,b,i
a="&H"
fori=0to3
b=Hex(iptemp(i))
iflen(b)=1then
b="0"&b
endif
a=a&b
next
ip2int=CLng(a)
endfunction
functionint2ip(ip)
dimiptemp,a,ipstr,i,length
iptemp=Hex(ip)
length=8-len(iptemp)
fori=1tolength
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
endfunction
dimtestIP,testInt
testIP="202.102.29.6"
testInt=ip2int(testIP)
response.writetestIP&"willbeencodedto<fontcolor=red>"&testInt&"</font><br>"
response.writetestIP&"willbedencodedto<fontcolor=red>"&int2ip(testInt)&"</font><br>"