Les Snippets

Connexion

IPV4 IPV6 vers chaine et chaine vers IPV4 IPV6

Niveau requis pour utiliser/comprendre cette source : 2 ( Initié )
Créé le 15/09/2008 16:18:46 et initié par f0xi [Liste]
Date de mise à jour : 15/09/2008 16:19:49
Vue : 2048
Catégorie(s) : Trucs & Astuces, Algorithme, Chaîne de caractères, Divers, Web
Langages dispo pour ce code :
- Delphi 5



Langage : Delphi 5
Date ajout : 15/09/2008
Posté par f0xi [Liste]
DateMAJ : 15/09/2008
Type
  TIPFormat = (ifV4, ifV6);
  TIPV4 = array[0..3] of byte;
  TIPV6 = array[0..15] of byte;


// accept 0.0.0.0 to 255.255.255.255 function StrToIPV4(const S: string): TIPV4; var L, N, I, U : integer; const   CTB : array['0'..'9'] of byte = (0,1,2,3,4,5,6,7,8,9); begin   L := Length(S);   Assert((L > 6) and (L < 16), 'Error : string is not IPV4.');   I := 0;   U := 0;   for N := 1 to Length(S) do   begin     case S[N] of       '0'..'9': begin         case U of           0    : result[I] := CTB[S[N]];           1..2 : result[I] := CTB[S[N]] + (result[I]*10);         end;         inc(U);         assert(U < 4, 'Error : string is not IPV4.');       end;       '.' : begin          inc(I);          U := 0;       end;     end;   end; end; // return 0.0.0.0 to 255.255.255.255 function IPV4ToStr(const IP: TIPV4): string; begin   result := format(    '%d.%d.%d.%d',    [ IP[0],IP[1],IP[2],IP[3] ]   ); end;
// accept 0000:0000:0000:0000:0000:0000:0000:0000 to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff function StrToIPV6(const S: string): TIPV6; var   N,I,H,L : integer; const   CNTB : array['0'..'9'] of byte = (0,1,2,3,4,5,6,7,8,9);   CHTB : array['a'..'f'] of byte = ($a,$b,$c,$d,$e,$f); begin   L := Length(S);   Assert(L = 39, 'Error: string is not IPV6');   I := 0;   H := 0;   for N := 1 to L do   begin     case S[N] of       '0'..'9' : begin         case H of           0 : result[I] := CNTB[S[N]];           1 : result[I] := (result[I] shl 4) or CNTB[S[N]];         end;         inc(H);       end;       'a'..'f' : begin         case H of           0 : result[I] := CHTB[S[N]];           1 : result[I] := (result[I] shl 4) or CHTB[S[N]];         end;         inc(H);       end;     end;     if H > 1 then     begin       inc(I);       H := 0;     end;   end; end; // return 0000:0000:0000:0000:0000:0000:0000:0000 to ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff function IPV6ToStr(const IP: TIPV6): string; const   HXTSTR : array[0..$F] of char = '0123456789abcdef'; begin   SetLength(result, 39);   //loop unfolded   result[1]  := HXTSTR[IP[0] shr 4];   result[2]  := HXTSTR[IP[0] and $F];   result[3]  := HXTSTR[IP[1] shr 4];   result[4]  := HXTSTR[IP[1] and $F];   result[5]  := ':';   result[6]  := HXTSTR[IP[2] shr 4];   result[7]  := HXTSTR[IP[2] and $F];   result[8]  := HXTSTR[IP[3] shr 4];   result[9]  := HXTSTR[IP[3] and $F];   result[10] := ':';   result[11] := HXTSTR[IP[4] shr 4];   result[12] := HXTSTR[IP[4] and $F];   result[13] := HXTSTR[IP[5] shr 4];   result[14] := HXTSTR[IP[5] and $F];   result[15] := ':';   result[16] := HXTSTR[IP[6] shr 4];   result[17] := HXTSTR[IP[6] and $F];   result[18] := HXTSTR[IP[7] shr 4];   result[19] := HXTSTR[IP[7] and $F];   result[20] := ':';   result[21] := HXTSTR[IP[8] shr 4];   result[22] := HXTSTR[IP[8] and $F];   result[23] := HXTSTR[IP[9] shr 4];   result[24] := HXTSTR[IP[9] and $F];   result[25] := ':';   result[26] := HXTSTR[IP[10] shr 4];  result[27] := HXTSTR[IP[10] and $F];   result[28] := HXTSTR[IP[11] shr 4];  result[29] := HXTSTR[IP[11] and $F];   result[30] := ':';   result[31] := HXTSTR[IP[12] shr 4];  result[32] := HXTSTR[IP[12] and $F];   result[33] := HXTSTR[IP[13] shr 4];  result[34] := HXTSTR[IP[13] and $F];   result[35] := ':';   result[36] := HXTSTR[IP[14] shr 4];  result[37] := HXTSTR[IP[14] and $F];   result[38] := HXTSTR[IP[15] shr 4];  result[39] := HXTSTR[IP[15] and $F]; end;

Snippets en rapport avec : Ip, Ipv4, Ipv6, Iptostr, Strtoip



Codes sources en rapport avec : Ip, Ipv4, Ipv6, Iptostr, Strtoip

{} EXTRACTION DES ADRESSES IP
Permet tout simplement d'extraire les adresses IP d'un texte. Valide: 192.168.0.1 ss 127.0.0....

{} VALIDATEUR IPV6
valide une adresse IPV6 (format hexadécimale) dans l'intervalle : 0000:0000:0000:0000:0000:0000:0...

{} VALIDATEUR IPV4
Permet de tester la validité d'une chaine representant une adresse IPv4, telle que 127.0.0.1 ou 192....

{Visual Basic, VB6, VB.NET, VB 2005} MASTERLOCATER.NET
Cette source vous donne quulque information regionnal a partir de votre addresse IP.utilisation des ...

{Python} SCANNEUR D'IP21
Voilà, c'est un petit scanneur de pub, Il est en ligne de commande ce qui permet de l'utiliser en...

{C / C++ / C++.NET} CRYPTEUR-DÉCRYPTEUR-IP
Logiciel qui pourra vous servir a crypter votre adresse IP et par la suite le décrypter avec l'app...

{Python} SIMPLE COMPARATEUR IPV4 EN PYTHON
Comparaison de deux adresses IPv4 pour determiner si elles sont sur le meme sous reseau. Le script e...

{Visual Basic, VB6, VB.NET, VB 2005} CALCULATEUR DE SOUS RESEAUX IP.
Programme qui permet a partir d'une ip est d'un masque de caculer (reelement avec operation logique ...

{PHP} VERIFICATION D'UNE ADRESSE IP
Verification si une adresse IP [$atester] est a l'intérieur d'une plage d'adresses donnée [$debut,$f...

{Visual Basic, VB6, VB.NET, VB 2005} [VB.NET 2008] ACTIVATION DE LOGICIEL AVEC PHP ET MYSQL BETA 1
mon application sert a enregistrer/activer des produits c'est tres simple il suffit d'avoir une base...