ASP, IP address segment calculation

Source: Internet
Author: User
<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", ",") in vbs, you will get three numbers: 202,102 and 29, but not the last six, therefore, 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" &
I = CInt ()
A = CStr (I)
Ipstr = &"."
A = mid (iptemp, 3, 2)
A = "& H" &
I = CInt ()
A = CStr (I)
Ipstr = ipstr & &"."
A = mid (iptemp, 5, 2)
A = "& H" &
I = CInt ()
A = CStr (I)
Ipstr = ipstr & &"."
A = right (iptemp, 2)
Related Keywords:
Related Article E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth \$300-1200 USD