ASP, 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", ",") 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)
A = "& H" &
I = CINT ()
A = CSTR (I)
Ipstr = ipstr &
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>"
%>