Help!!!!

Résolu
bayroom Messages postés 12 Date d'inscription mercredi 12 septembre 2007 Statut Membre Dernière intervention 12 décembre 2007 - 26 sept. 2007 à 10:13
bayroom Messages postés 12 Date d'inscription mercredi 12 septembre 2007 Statut Membre Dernière intervention 12 décembre 2007 - 28 sept. 2007 à 12:22
Salut tout le monde, bon je fait un projet de sniffer+routteur en java, la partie sniff c'est OK mais le probléme est avec la partie routeur...
J'ai trouvé un exemple en VB mais je n'arrive pas à le comprendre alors si vous pouvez me donner un coup de main et le recoder en java ou m'aider à le faire, je pollue je sait mais je suit vraiment dans l'impasse...Merci à tous...... 
Voici le code du routeur en VB;
Public Sub Routes_Paquets(xProto As Byte, Donnee As String)
'  on va router un paquet avec une nouvelle ip de destination
On Error Resume Next
'on active ou désactive la prise en charge du protocole pour le routageIf Form1.OptionRouteur(2).Value 0 Then If xProto 1 Then xProto = 0 ' icmpIf Form1.OptionRouteur(1).Value 0 Then If xProto 17 Then xProto = 0 ' udpIf Form1.OptionRouteur(0).Value 0 Then If xProto 6 Then xProto = 0 ' tcp
' on charge dans notre nouvelle entête eip,l'entete ip qu'on vient juste de sniffer
With eIP ' entête ip
        .VerLen = &H45
        .id = xEnteteIp.id
        .Offset = xEnteteIp.Offset
        .Ttl = xEnteteIp.Ttl
        .SourceIp = inet_addr(Form1.txtRouteur(0).Text) ' <-- nouvelle ip source
        .DestIp = inet_addr(Form1.txtRouteur(1).Text) '<-- nouvelle ip destination
        .Protocol = xProto
        .Tos = xEnteteIp.Tos
        .Checksum = 0 ' <--- nouveau checksum à recalculé
        .Checksum = UnsignedToInteger(Check.Checksum(VarPtr(eIP), LenB(eIP)))
End With


If eIP.Protocol 6 Or eIP.Protocol 17 Then 'pseudo entete uniquement pour tcp ou udp
    ' pseudo entête uniquement pour le calcule du checksum
    With ePS
            .IPsource = eIP.SourceIp
            .IPdestination = eIP.DestIp
            .Protocol = eIP.Protocol
            .Reserved = 0
    End With
End If


Select Case xProto
Case 6 ' = TCP
        ePS.Len = ntohs(LenB(eTCP) + UBound(xData)) '<- taille  pseudoEntete
    With eTCP
        .Ack = xEnteteTcp.Ack
        .DataOffset = xEnteteTcp.DataOffset
        .Flag = xEnteteTcp.Flag
        .PortDesti = xEnteteTcp.PortDesti
        .PortSource = xEnteteTcp.PortSource
        .Sequence = xEnteteTcp.Sequence
        .UrgentPointer = xEnteteTcp.UrgentPointer
        .Windows = xEnteteTcp.Windows
        .Checksum = 0
        .Checksum = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)))
   End With
    eIP.TotalLength = ntohs(LenB(eIP) + LenB(eTCP) + UBound(xData)) ' taille entête ip
Case 17 ' = UDP
        ePS.Len = ntohs(LenB(eUDP) + UBound(xData))
    With eUDP ' on garde les mêmes valeurs du paquet qu'on à sniffer pour notre nouvelle entête
            .SourcePort = xEnteteUdp.SourcePort
            .DestPort = xEnteteUdp.DestPort
            .udpChecksum = 0
            .Len = ePS.Len ' <- nouvelle taille de l'entête udp
    End With
        'on calcule le checksum pour l'entete udp
        eUDP.udpChecksum = UnsignedToInteger(CheckUdp(VarPtr(ePS), LenB(ePS), VarPtr(eUDP), LenB(eUDP), VarPtr(xData(0)), UBound(xData)))
        eIP.TotalLength = ntohs((LenB(eIP) + LenB(eUDP) + UBound(xData))) ' taille entête ip
Case 1 ' = ICMP
    With eICMP ' entête icmp , on garde les mêmes valeurs
            .Type = xEnteteIcmp.Type
            .Code = xEnteteIcmp.Code
            .Identifiant = xEnteteIcmp.Identifiant
            .Sequence = xEnteteIcmp.Sequence
            .Checksum = xEnteteIcmp.Checksum
    End With
        eIP.TotalLength = ntohs(LenB(eIP) + LenB(eICMP) + UBound(xData)) ' taille entête ip
End Select


Dim xPaquet() As Byte ' on forge notre trame = Entête ip + datagramme(entête tcp ou icmp ou udp +data)
Select Case xProto
Case 6 'on forge un  paquet TCP
        ReDim xPaquet(LenB(eIP) + LenB(eTCP) + UBound(xData))
        CopyMemory ByVal VarPtr(xPaquet(0)), ByVal VarPtr(eIP), LenB(eIP)
        CopyMemory ByVal VarPtr(xPaquet(LenB(eIP))), ByVal VarPtr(eTCP), LenB(eTCP)
        CopyMemory ByVal VarPtr(xPaquet(LenB(eIP) + LenB(eTCP))), ByVal VarPtr(xData(0)), UBound(xData)
Case 17 'on forge un  paquet UDP
        ReDim xPaquet(LenB(eIP) + LenB(eUDP) + UBound(xData))
        CopyMemory ByVal VarPtr(xPaquet(0)), ByVal VarPtr(eIP), LenB(eIP)
        CopyMemory ByVal VarPtr(xPaquet(LenB(eIP))), ByVal VarPtr(eUDP), LenB(eUDP)
        CopyMemory ByVal VarPtr(xPaquet(LenB(eIP) + LenB(eUDP))), ByVal VarPtr(xData(0)), UBound(xData)
Case 1 ' on forge un paquet ICMP
        ReDim xPaquet(LenB(eIP) + LenB(eICMP) + UBound(xData))
        CopyMemory ByVal VarPtr(xPaquet(0)), ByVal VarPtr(eIP), LenB(eIP)
         CopyMemory ByVal VarPtr(xPaquet(LenB(eIP))), ByVal VarPtr(eICMP), LenB(eICMP)
        CopyMemory ByVal VarPtr(xPaquet(LenB(eIP) + LenB(eICMP))), ByVal VarPtr(xData(0)), UBound(xData)
End Select
' structure de destinantion
Call CreateSocket(VarPtr(xPaquet(0)), CInt(xProto))
    Dim SockAddr As SOCK_ADDR
        SockAddr.sin_zero(0) = 0
        SockAddr.sin_family = AF_INET '<-famille protocole        If xProto 6 Then SockAddr.sin_port xEnteteTcp.PortDesti   ' port de destination pour tcp        If xProto 17 Then SockAddr.sin_port xEnteteUdp.DestPort ' port de destination pour udp
        ' <-------------- rien pour icmp,pas de port ------------------------->
        SockAddr.sin_addr.S_addr = eIP.DestIp ' adresse de destination
' la fonction Sendto va nous permettre d'envoyer un paquet à une adresse spécifiée par la structure to de type sockaddr.
SendData = sendto(zSock, ByVal VarPtr(xPaquet(0)), UBound(xPaquet), 0, SockAddr, LenB(SockAddr))
If SendData > 0 Then
Debug.Print "envoi réussi"
' Compteur de paquet router
Select Case xProto ' mise à jour
Case 1
        Form1.OptionRouteur(2).Tag = Form1.OptionRouteur(2).Tag + 1
        Form1.OptionRouteur(2).Caption = "ICMP (" & Form1.OptionRouteur(2).Tag & ")"
Case 17
        Form1.OptionRouteur(1).Tag = Form1.OptionRouteur(1).Tag + 1
        Form1.OptionRouteur(1).Caption = "UDP (" & Form1.OptionRouteur(1).Tag & ")"
Case 6
        Form1.OptionRouteur(0).Tag = Form1.OptionRouteur(0).Tag + 1
        Form1.OptionRouteur(0).Caption = "TCP (" & Form1.OptionRouteur(0).Tag & ")"
End SelectForm1.Label2(4).Tag Form1.Label2(4).Tag + 1: Form1.Label2(4).Caption "ROUTE : " & Form1.Label2(4).Tag
Else
Debug.Print "erreur envoi"
End If
Call ListePaquet(Donnee, CInt(xProto))
End Sub
Public Sub CreateSocket(adrs As Long, Proto As Integer)
Dim StartupInfo As WSA_DATA
    WSAStartup &H202, StartupInfoIf Proto 6 Or Proto 1 Then zSock = socket(AF_INET, SOCK_RAW, Proto) Else zSock = socket(AF_INET, SOCK_DGRAM, 17)
    setsockopt zSock, IPPROTO_IP, IP_HDRINCL, adrs, 4
End Sub
Sub ListePaquet(xData As String, Proto As Integer)
Dim Parent    As Node, EnteteA As Node, EnteteB As Node, flags As Node, Titre As String, Info As String


If Proto 6 Then Titre "Entete Tcp" Else If Proto = 17 Then Titre = "Entete Udp" Else Titre = "Entete Icmp"Info FonctionIp(eIP.SourceIp) & " --> " & FonctionIp(eIP.DestIp) & Space(10) & IIf(Proto 1, vbNullString, Mid(xData, 1, 70) & "...")
    ' on quitte si le protocole ne correspond pas à TCP Or UDP Or ICMP
    If Proto <> 6 And Proto <> 17 And Proto <> 1 Then Exit Sub
        Set Parent Form1.Tree(2).Nodes.Add(): Parent Info: Parent.Image = 1    Set EnteteA Form1.Tree(2).Nodes.Add(Parent, tvwChild): EnteteA "Entete ip": EnteteA.Image = 2    Set EnteteB Form1.Tree(2).Nodes.Add(Parent, tvwChild): EnteteB Titre: EnteteB.Image = 2
  
Parent.Tag = xData
EnteteA.Tag = xEnteteIp.SourceIp
   
    With eIP ' on affiche les valeurs des entetes ip
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Source IP  . . . . . . . . . " & FonctionIp(.SourceIp), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Destination IP . . . . . . . . . " & FonctionIp(.DestIp), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Time To Live (TTL) . . . . . . . . . " & .Ttl, 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "IP Version . . . . . . . . .IPv" & HiNibble(.VerLen), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Identification . . . . . . . . . " & IntegerToUnsigned(.id), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "DataOffset. . . . . . . . ." & IntegerToUnsigned(ntohs(.Offset)), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Checksum . . . . . . . . . " & IntegerToUnsigned(ntohs(.Checksum)), 3
        Form1.Tree(2).Nodes.Add EnteteA, tvwChild, , "Longueur . . . . . . . . . " & ntohs(.TotalLength), 3
    End With
   
Select Case Proto
Case 1
        With eICMP ' ICMP
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Type. . . . . . . . . " & IcmpTypeValeur(.Type), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Code . . . . . . . . ." & IcmpCodeValeur(.Type, .Code), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Checksum . . . . . . . ." & IntegerToUnsigned(ntohs(.Checksum)), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Identifiant. . . . . . . . ." & ntohl(.Identifiant), 3
        End With
Case 6
        With eTCP ' TCP
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Source Port. . . . . . . . ." & ntohs(.PortSource), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Dest Port. . . . . . . . ." & ntohs(.PortDesti), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "DataOffset. . . . . . . . ." & IntegerToUnsigned(ntohs(.DataOffset)), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Ack. . . . . . . . ." & LongToUnsigned(ntohl(.Ack)), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Sequence. . . . . . . . ." & LongToUnsigned(ntohl(.Sequence)), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Urgent Pointer. . . . . . . . ." & ntohs(.UrgentPointer), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Windows. . . . . . . . ." & ntohs(.Windows), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Checksum . . . . . . . . ." & IntegerToUnsigned(ntohs(.Checksum)), 3
        End With
Case 17
        With eUDP ' UDP
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Source Port. . . . . . . . ." & ntohs(.SourcePort), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Dest Port. . . . . . . . ." & ntohs(.DestPort), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Longueur. . . . . . . . ." & ntohs(.Len), 3
            Form1.Tree(2).Nodes.Add EnteteB, tvwChild, , "Checksum. . . . . . . . ." & IntegerToUnsigned(ntohs(.udpChecksum)), 3
         End With
End Select
End Sub

3 réponses

cs__Syl_ Messages postés 66 Date d'inscription vendredi 20 octobre 2006 Statut Membre Dernière intervention 25 février 2008 2
26 sept. 2007 à 11:45
Bonjour,

Voilà le code traduit en C#, la syntaxe de java et de C# étant proche (plus en tout cas que VB et java) ca devrait t'aider un peu.

public void Routes_Paquets(byte xProto, string Donnee) {
// on va router un paquet avec une nouvelle ip de destination
// TODO: On Error Resume Next Warning!!!: The statement is not translatable
if ((Form1.OptionRouteur(2).Value == 0)) {
if ((xProto == 1)) {
xProto = 0;
}
}
// icmp
if ((Form1.OptionRouteur(1).Value == 0)) {
if ((xProto == 17)) {
xProto = 0;
}
}
// udp
if ((Form1.OptionRouteur(0).Value == 0)) {
if ((xProto == 6)) {
xProto = 0;
}
}
// tcp
// on charge dans notre nouvelle ent�te eip,l'entete ip qu'on vient juste de sniffer
// With...
// ent�te ip
xEnteteIp.Ttl.SourceIp = inet_addr(Form1.txtRouteur(0).Text);
xEnteteIp.Offset.Ttl = inet_addr(Form1.txtRouteur(0).Text);
xEnteteIp.id.Offset = inet_addr(Form1.txtRouteur(0).Text);
69.id = inet_addr(Form1.txtRouteur(0).Text);
eIP.VerLen = inet_addr(Form1.txtRouteur(0).Text);
// <-- nouvelle ip source
eIP.DestIp = inet_addr(Form1.txtRouteur(1).Text);
// <-- nouvelle ip destination
xEnteteIp.Tos.Checksum = 0;
xProto.Tos = 0;
eIP.Protocol = 0;
// <--- nouveau checksum � recalcul�
eIP.Checksum = UnsignedToInteger(Check.Checksum(VarPtr(eIP), LenB(eIP)));
if (((eIP.Protocol == 6)
|| (eIP.Protocol == 17))) {
// pseudo entete uniquement pour tcp ou udp
// pseudo ent�te uniquement pour le calcule du checksum
// With...
eIP.DestIp.Protocol = 0;
eIP.SourceIp.IPdestination = 0;
ePS.IPsource = 0;
}
switch (xProto) {
case 6:
// = TCP
ePS.Len = ntohs((LenB(eTCP) + UBound(xData)));
// <- taille pseudoEntete
// With...
xEnteteTcp.Windows.Checksum = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.UrgentPointer.Windows = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.Sequence.UrgentPointer = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.PortSource.Sequence = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.PortDesti.PortSource = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.Flag.PortDesti = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.DataOffset.Flag = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
xEnteteTcp.Ack.DataOffset = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
eTCP.Ack = UnsignedToInteger(CheckTcp(VarPtr(ePS), LenB(ePS), VarPtr(eTCP), LenB(eTCP), VarPtr(xData(0)), UBound(xData)));
eIP.TotalLength = ntohs((LenB(eIP)
+ (LenB(eTCP) + UBound(xData))));
// taille ent�te ip
break;
case 17:
// = UDP
ePS.Len = ntohs((LenB(eUDP) + UBound(xData)));
// With...
// on garde les m�mes valeurs du paquet qu'on � sniffer pour notre nouvelle ent�te
0.Len = ePS.Len;
xEnteteUdp.DestPort.udpChecksum = ePS.Len;
xEnteteUdp.SourcePort.DestPort = ePS.Len;
eUDP.SourcePort = ePS.Len;
// <- nouvelle taille de l'ent�te udp
// on calcule le checksum pour l'entete udp
eUDP.udpChecksum = UnsignedToInteger(CheckUdp(VarPtr(ePS), LenB(ePS), VarPtr(eUDP), LenB(eUDP), VarPtr(xData(0)), UBound(xData)));
eIP.TotalLength = ntohs((LenB(eIP)
+ (LenB(eUDP) + UBound(xData))));
// taille ent�te ip
break;
case 1:
// = ICMP
// With...
// ent�te icmp , on garde les m�mes valeurs
xEnteteIcmp.Sequence.Checksum = xEnteteIcmp.Checksum;
xEnteteIcmp.Identifiant.Sequence = xEnteteIcmp.Checksum;
xEnteteIcmp.Code.Identifiant = xEnteteIcmp.Checksum;
xEnteteIcmp.Type.Code = xEnteteIcmp.Checksum;
eICMP.Type = xEnteteIcmp.Checksum;
eIP.TotalLength = ntohs((LenB(eIP)
+ (LenB(eICMP) + UBound(xData))));
// taille ent�te ip
break;
}
byte[] xPaquet;
// on forge notre trame = Ent�te ip + datagramme(ent�te tcp ou icmp ou udp +data)
switch (xProto) {
case 6:
// on forge un paquet TCP
object xPaquet;
CopyMemory;
VarPtr(xPaquet[0]);
VarPtr(eIP);
LenB(eIP);
CopyMemory;
VarPtr(xPaquet[LenB(eIP)]);
VarPtr(eTCP);
LenB(eTCP);
CopyMemory;
VarPtr(xPaquet[(LenB(eIP) + LenB(eTCP))]);
VarPtr(xData(0));
UBound(xData);
break;
case 17:
// on forge un paquet UDP
object xPaquet;
CopyMemory;
VarPtr(xPaquet[0]);
VarPtr(eIP);
LenB(eIP);
CopyMemory;
VarPtr(xPaquet[LenB(eIP)]);
VarPtr(eUDP);
LenB(eUDP);
CopyMemory;
VarPtr(xPaquet[(LenB(eIP) + LenB(eUDP))]);
VarPtr(xData(0));
UBound(xData);
break;
case 1:
// on forge un paquet ICMP
object xPaquet;
CopyMemory;
VarPtr(xPaquet[0]);
VarPtr(eIP);
LenB(eIP);
CopyMemory;
VarPtr(xPaquet[LenB(eIP)]);
VarPtr(eICMP);
LenB(eICMP);
CopyMemory;
VarPtr(xPaquet[(LenB(eIP) + LenB(eICMP))]);
VarPtr(xData(0));
UBound(xData);
break;
}
// structure de destinantion
CreateSocket(VarPtr(xPaquet[0]), int.Parse(xProto));
SOCK_ADDR SockAddr;
SockAddr.sin_zero(0) = 0;
SockAddr.sin_family = AF_INET;
// <-famille protocole
if ((xProto == 6)) {
SockAddr.sin_port = xEnteteTcp.PortDesti;
}
// port de destination pour tcp
if ((xProto == 17)) {
SockAddr.sin_port = xEnteteUdp.DestPort;
}
// port de destination pour udp
// <-------------- rien pour icmp,pas de port ------------------------->
SockAddr.sin_addr.S_addr = eIP.DestIp;
// adresse de destination
// la fonction Sendto va nous permettre d'envoyer un paquet � une adresse sp�cifi�e par la structure to de type sockaddr.
SendData = sendto(zSock, VarPtr(xPaquet[0]), UBound(xPaquet), 0, SockAddr, LenB(SockAddr));
if ((SendData > 0)) {
Debug.Print;
"envoi r�ussi";
switch (xProto) {
case 1:
Form1.OptionRouteur(2).Tag = (Form1.OptionRouteur(2).Tag + 1);
Form1.OptionRouteur(2).Caption = ("ICMP ("
+ (Form1.OptionRouteur(2).Tag + ")"));
break;
case 17:
Form1.OptionRouteur(1).Tag = (Form1.OptionRouteur(1).Tag + 1);
Form1.OptionRouteur(1).Caption = ("UDP ("
+ (Form1.OptionRouteur(1).Tag + ")"));
break;
case 6:
Form1.OptionRouteur(0).Tag = (Form1.OptionRouteur(0).Tag + 1);
Form1.OptionRouteur(0).Caption = ("TCP ("
+ (Form1.OptionRouteur(0).Tag + ")"));
break;
}
Form1.Label2(4).Tag = (Form1.Label2(4).Tag + 1);
Form1.Label2(4).Caption = ("ROUTE : " + Form1.Label2(4).Tag);
}
else {
Debug.Print;
"erreur envoi";
}
ListePaquet(Donnee, int.Parse(xProto));
}

public void CreateSocket(long adrs, int Proto) {
WSA_DATA StartupInfo;
WSAStartup;
514;
StartupInfo;
if (((Proto == 6)
|| (Proto == 1))) {
zSock = socket(AF_INET, SOCK_RAW, Proto);
}
else {
zSock = socket(AF_INET, SOCK_DGRAM, 17);
}
setsockopt;
zSock;
IPPROTO_IP;
IP_HDRINCL;
adrs;
4;
}

void ListePaquet(string xData, int Proto) {
Node Parent;
Node EnteteA;
Node EnteteB;
Node flags;
string Titre;
string Info;
if ((Proto == 6)) {
Titre = "Entete Tcp";
}
else if ((Proto == 17)) {
Titre = "Entete Udp";
}
else {
Titre = "Entete Icmp";
}
Info = (FonctionIp(eIP.SourceIp) + (" --> "
+ (FonctionIp(eIP.DestIp)
+ (Space(10) + ( (Proto == 1) ? null : (xData.Substring(0, 70) + "...") )))));
// on quitte si le protocole ne correspond pas � TCP Or UDP Or ICMP
if (((Proto != 6)
&& ((Proto != 17)
&& (Proto != 1)))) {
return;
}
Parent = Form1.Tree(2).Nodes.Add();
Parent = Info;
Parent.Image = 1;
EnteteA = Form1.Tree(2).Nodes.Add(Parent, tvwChild);
EnteteA = "Entete ip";
EnteteA.Image = 2;
EnteteB = Form1.Tree(2).Nodes.Add(Parent, tvwChild);
EnteteB = Titre;
EnteteB.Image = 2;
Parent.Tag = xData;
EnteteA.Tag = xEnteteIp.SourceIp;
// With...
// on affiche les valeurs des entetes ip
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Source IP . . . . . . . . . " + FonctionIp(eIP.SourceIp));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Destination IP . . . . . . . . . " + FonctionIp(eIP.DestIp));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Time To Live (TTL) . . . . . . . . . " + eIP.Ttl);
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("IP Version . . . . . . . . .IPv" + HiNibble(eIP.VerLen));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Identification . . . . . . . . . " + IntegerToUnsigned(eIP.id));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("DataOffset. . . . . . . . ." + IntegerToUnsigned(ntohs(eIP.Offset)));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Checksum . . . . . . . . . " + IntegerToUnsigned(ntohs(eIP.Checksum)));
3;
Form1.Tree(2).Nodes.Add;
EnteteA;
tvwChild;
("Longueur . . . . . . . . . " + ntohs(eIP.TotalLength));
3;
switch (Proto) {
case 1:
// With...
// ICMP
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Type. . . . . . . . . " + IcmpTypeValeur(eICMP.Type));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Code . . . . . . . . ." + IcmpCodeValeur(eICMP.Type, eICMP.Code));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Checksum . . . . . . . ." + IntegerToUnsigned(ntohs(eICMP.Checksum)));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Identifiant. . . . . . . . ." + ntohl(eICMP.Identifiant));
3;
break;
case 6:
// With...
// TCP
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Source Port. . . . . . . . ." + ntohs(eTCP.PortSource));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Dest Port. . . . . . . . ." + ntohs(eTCP.PortDesti));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("DataOffset. . . . . . . . ." + IntegerToUnsigned(ntohs(eTCP.DataOffset)));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Ack. . . . . . . . ." + LongToUnsigned(ntohl(eTCP.Ack)));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Sequence. . . . . . . . ." + LongToUnsigned(ntohl(eTCP.Sequence)));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Urgent Pointer. . . . . . . . ." + ntohs(eTCP.UrgentPointer));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Windows. . . . . . . . ." + ntohs(eTCP.Windows));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Checksum . . . . . . . . ." + IntegerToUnsigned(ntohs(eTCP.Checksum)));
3;
break;
case 17:
// With...
// UDP
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Source Port. . . . . . . . ." + ntohs(eUDP.SourcePort));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Dest Port. . . . . . . . ." + ntohs(eUDP.DestPort));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Longueur. . . . . . . . ." + ntohs(eUDP.Len));
3;
Form1.Tree(2).Nodes.Add;
EnteteB;
tvwChild;
("Checksum. . . . . . . . ." + IntegerToUnsigned(ntohs(eUDP.udpChecksum)));
3;
break;
}
}


pour info, voici le lien d'un traducteur VB->C# : http://www.carlosag.net/Tools/CodeTranslator/Default.aspx

En esperant avoir aidé un peu

Bonne fin de journée
3
sheorogath Messages postés 2448 Date d'inscription samedi 21 février 2004 Statut Modérateur Dernière intervention 29 janvier 2010 17
26 sept. 2007 à 15:44
je dit rien pour cette fois ( un peu la flemme de faire la police)

mais bon la prochaine fois mais un titre plus clair
ta de la chance d'avoir eut une reponse car perso je pense pas que beacoup de monde fasse du VB ici...

mais bon apres ta ete polis et on vois que ta fais un peu de recherche donc c'est aussi une des raison pour laquel je dis rien ^^

ps : pas la peine de recommencer si possible autant te faire expliquer le code sur VBfrance ^^

"n'est pas mort ce qui semble a jamais dormir et en d'etrange temps meme la mort peut mourrir"
0
bayroom Messages postés 12 Date d'inscription mercredi 12 septembre 2007 Statut Membre Dernière intervention 12 décembre 2007
28 sept. 2007 à 12:22
Je vous présente toutes mes excuses pour le mal que j'ai fait, je ne savais pas quoi faire et j'ai perdu beaucoup de temp à chercher sans trouver, la prochaine fois je veillerais à mieux respecter le reglement, désolé encore...




A présent il va me faloir demander encore de l'aide pour trouver comment exprimer ma gratitude enver _Syl_; vous m'avez beaucoup aidé et encore merci pour le traducteur, j'épère bien avoir la chance de vous rendre ce service un jour...
 
0
Rejoignez-nous