Analyse de trame ip avec java

momouna Messages postés 8 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 7 mars 2016 - 7 mars 2016 à 12:45
 Utilisateur anonyme - 31 mars 2016 à 19:09
Bonjour,
je souhaiterais pouvoir "Analyser" une trame que s'échange entre 2 machines lié par un cable croisé (et ce peu importe les protocoles (ICMP-IP-Ethernet)
c-a-d je cherche a dévelloper une apllication en java

je faire capter les trames par le jpcap puis il faut d'analyser
mon probléme maintenant:j'ai besoin du code java pour analyser le trame qui capté par le jpcap
Merci d'avance.

1 réponse

Utilisateur anonyme
31 mars 2016 à 19:09
Pour analyser un packet ip , une trame ethernet , un segment ou un message j'utilise une bibliothèque très puissante (Jnetpcap)

on suppose que vous avez une trame ethernet et que vous voulez l'analyser :


public static void main(String[] args) {
//On suppose que EthernetPacket est une trame athernet que vous avez capté
String EthernetFrame=" 001801bf 6adc0025 4bb7afec 08004500 "
+ " 0041a983 40004006 d69ac0a8 00342f8c "
+ " ca30c3ef 008f2e80 11f52ea8 4b578018 "
+ " ffffa6ea 00000101 080a152e ef03002a "
+ " 2c943538 322e3430 204e4f4f 500d0a";
//dans un lan tous les trames captées sont des trames ethernets
JPacket packet = new JMemoryPacket(JProtocol.ETHERNET_ID,EthernetFrame ) ;
//On analyse le protocole
System.out.println(packet);

}

Résultat:

Frame:
Frame: number = 0
Frame: timestamp = 2016-04-01 00:03:02.708
Frame: wire length = 79 bytes
Frame: captured length = 79 bytes
Frame:
Eth: ******* Ethernet - "Ethernet" - offset=0 (0x0) length=14 protocol suite=LAN
Eth:
Eth: destination = 00:18:01:bf:6a:dc
Eth: .... ..0. .... .... = [0] LG bit
Eth: .... ...0 .... .... = [0] IG bit
Eth: source = 00:25:4b:b7:af:ec
Eth: .... ..0. .... .... = [0] LG bit
Eth: .... ...0 .... .... = [0] IG bit
Eth: type = 0x800 (2048) [ip version 4]
Eth:
Ip: ******* Ip4 - "ip version 4" - offset=14 (0xE) length=20 protocol suite=NETWORK
Ip:
Ip: version = 4
Ip: hlen = 5 [5 * 4 = 20 bytes, No Ip Options]
Ip: diffserv = 0x0 (0)
Ip: 0000 00.. = [0] code point: not set
Ip: .... ..0. = [0] ECN bit: not set
Ip: .... ...0 = [0] ECE bit: not set
Ip: length = 65
Ip: id = 0xA983 (43395)
Ip: flags = 0x2 (2)
Ip: 0.. = [0] reserved
Ip: .1. = [1] DF: do not fragment: set
Ip: ..0 = [0] MF: more fragments: not set
Ip: offset = 0
Ip: ttl = 64 [time to live]
Ip: type = 6 [next: Transmission Control]
Ip: checksum = 0xD69A (54938) [correct]
Ip: source = 192.168.0.52
Ip: destination = 47.140.202.48
Ip:
Tcp: ******* Tcp offset=34 (0x22) length=32
Tcp:
Tcp: source = 50159
Tcp: destination = 143
Tcp: seq = 0x2E8011F5 (780145141)
Tcp: ack = 0x2EA84B57 (782781271)
Tcp: hlen = 8
Tcp: reserved = 0
Tcp: flags = 0x18 (24)
Tcp: 0... .... = [0] cwr: reduced (cwr)
Tcp: .0.. .... = [0] ece: ECN echo flag
Tcp: ..0. .... = [0] ack: urgent, out-of-band data
Tcp: ...1 .... = [1] ack: acknowledgment
Tcp: .... 1... = [1] ack: push current segment of data
Tcp: .... .0.. = [0] ack: reset connection
Tcp: .... ..0. = [0] ack: synchronize connection, startup
Tcp: .... ...0 = [0] fin: closing down connection
Tcp: window = 65535
Tcp: checksum = 0xA6EA (42730) [correct]
Tcp: urgent = 0
Tcp:
Tcp: + NoOp: offset=20 length=1
Tcp: code = 1
Tcp: length = 1 [implied length from option type]
Tcp:



Note : il faut ajouter jnetpcap-pcap100.dll et jnetpcap.dll a votre dossier jre1.x.x_mm\bin
et ajouter jnetpcap à votre path bien sûr
0
Rejoignez-nous