IP address segment Calculation
<Script language = "jscript" runat = "server">
Function ipdecode (EIP ){
VaR IP1, ip2, IP3, ip4;
IP1 = movebyter (EIP & 0xff000000, 3 );
Ip2 = movebyter (EIP & 0x00ff0000, 2 );
IP3 = movebyter (EIP & 0x0000ff00, 1 );
Ip4 = EIP & 0x000000ff;
Return IP1 + "." + ip2 + "." + IP3 + "." + ip4;
}
Function movebytel (Num, bytenum ){
Return num <= (bytenum * 8)
}
Function movebyter (Num, bytenum ){
Return num >>>= (bytenum * 8)
}
</SCRIPT>
There is no bit operation in vbs, so JS and vbs are used in a page, which is not good. If you use vbs, you can do it, but it is a bit too long, and pay attention to it, if you split ("202.102.29.6 ",". "), 202,102, 29, and not the last 6, so you need to change the IP address to split (" 202.102.29.6 "&". ",". ")
I am using vbs, because there is no bit operation, so it is quite troublesome.
<%
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 ()
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 = mid (iptemp, 3,2)
A =" & H "& A
I = CINT ()
A = CSTR (I)
ipstr = ipstr & &". "
A = mid (iptemp, 5, 2)
A =" & H "& A
I = CINT ()
A = CSTR (I)
ipstr = ipstr & &". "
A = right (iptemp, 2)
A =" & H "& A
I = CINT ()
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 <font color = Red>" & testint & "</font> <br>"
Response. Write testip & "will be dencoded to <font color = Red>" & int2ip (testint) & "</font> <br>"
%>