Calcul de segmentation d'adresse IP
<scriptLanguage = "jscript" runat = "server">
functionIpDcode (eip) {
varip1, ip2, ip3, ip4;
Ip1 = movebyter (eip & 0xff000000,3);
Ip2 = movebyter (eip & 0x00ff0000,2);
Ip3 = movebyter (eip & 0x0000ff00,1);
Ip4 = eip & 0x000000ff;
returnip1 + "." + ip2 + "." + ip3 + "." + ip4;
}
functionMoveBytel (num, bytenum) {
returnnum << = (partenum * 8)
}
functionMoveByter (num, bytenum) {
returnnum >>> = (partenum * 8)
}
</cript>
Il n'y a pas de fonctionnement dans VBS, il n'est donc pas bon d'utiliser JS et VBS dans une page. C'est aussi OK si vous utilisez VBS, mais c'est un peu verbeux. Et une chose est un peu perceptible. Si vous vous séparez ("202.102.29.6", ".") Dans VBS, vous obtiendrez trois numéros 202, 102 et 29, et vous n'obtiendrez pas les 6 derniers, vous devez donc changer IP en Split ("202.102.29.6" & ".". ")
Je l'ai fait avec VBS, et comme il n'y a pas de fonctionnement, c'est plus gênant
<%
fundep2int (ipstr)
Dimiptemp, max
iptemp = split (ipstr & ".", ".")
max = ubund (iptemp)
ifmax <> 4Then
sortie
endire
dima, b, je
a = "& h"
fori = 0to3
b = hex (iptemp (i))
iflen (b) = 1Then
b = "0" et b
endire
a = a & b
suivant
ip2int = clng (a)
finition de fin
functionint2ip (ip)
Dimiptemp, A, ipstr, i, longueur
iptemp = hex (ip)
Longueur = 8-Len (iptemp)
fori = 1tolegle
iptemp = "0" & iptemp
suivant
a = gauche (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 = à droite (iptemp, 2)
a = "& h" & a
i = cint (a)
a = cstr (i)
ipstr = ipstr & a
int2ip = ipstr
finition de fin
dimtestip, testint
testip = "202.102.29.6"
TESTINT = IP2Int (Testrip)
Response.WriteStip & "Willbeencodedto <fontColor = Red>" & Testint & "</font> <br>"
Response.WriteStip & "WillbeDencodedto <FontColor = Red>" & int2ip (Testint) & "</font> <br>"