Perhitungan Segmentasi Alamat IP
<scriptLanguage = "jscript" runat = "server">
functipDecode (EIP) {
VARIP1, IP2, IP3, IP4;
IP1 = Movyter (EIP & 0XFF000000,3);
IP2 = Movyter (EIP & 0x00FF0000,2);
IP3 = Movyter (EIP & 0x0000FF00,1);
IP4 = EIP & 0x000000FF;
returnip1+"."+ip2+"."+ip3+"."+ip4;
}
functionmovebytel (num, bytenum) {
ReturnNum << = (Bytenum*8)
}
functionMoverbyter (num, hytenum) {
ReturnNum >>> = (Bytenum*8)
}
</script>
Tidak ada operasi bit di VBS, jadi tidak baik menggunakan JS dan VBS di halaman. Tidak apa -apa jika Anda menggunakan VBS, tetapi sedikit bertele -tele. Dan satu hal sedikit terlihat. Jika Anda berpisah ("202.102.29.6", ".") Dalam VBS, Anda akan mendapatkan tiga angka 202, 102, dan 29, dan Anda tidak akan mendapatkan 6 terakhir, jadi Anda perlu mengubah IP untuk membagi ("202.102.29.6" & ".", "
Saya melakukannya dengan VBS, dan karena tidak ada operasi bit, itu lebih merepotkan
<%
functip2int (ipstr)
Dimiptemp, maks
iptemp = split (ipstr & ".", ".")
max = ubund (iptemp)
Ifmax <> 4then
fungsi keluar
endif
Dima, b, i
a = "& h"
fori = 0to3
b = hex (iptemp (i))
iflen (b) = 1then
b = "0" & b
endif
A = A & B.
Berikutnya
ip2int = clng (a)
fungsi endfungsi
functionint2ip (ip)
Dimiptemp, a, ipstr, i, length
iptemp = hex (ip)
panjang = 8-len (iptemp)
fori = 1Tolength
IPTEMP = "0" & IPTEMP
Berikutnya
a = kiri (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 = kanan (iptemp, 2)
a = "& h" & a
i = cint (a)
a = cstr (i)
ipstr = ipstr & a
int2ip = ipstr
fungsi endfungsi
Dimtestip, testint
testip = "202.102.29.6"
TestInt = IP2Int (Testip)
response.writetestip & "willeencodedto <fontcolor = red>" & testint & "</font> <br>"
response.writetestip & "WillbedEncodedto <fontColor = red>" & int2ip (testint) & "</font> <br>"