IP address |ip address <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 the VBS, so in a page with JS and VBS, and not good, if the VBS can also, but wordy some, and a little note, if in the VBS split ("202.102.29.6", "."), will get 202,102, 293 number, Not get the last 6, so you need to replace the IP with split ("202.102.29.6" & ".", ".")
I do with the VBS, because there is no bit operation, so do more trouble
<%
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 & "'ll be encoded to <font color=red>" & Testint & "</font><br>"
Response.Write Testip & "'ll be dencoded to <font color=red>" & Int2ip (Testint) & "</font><br > "
%>