File tree Expand file tree Collapse file tree
src/main/java/com/javahelps/pcapparser Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <project xmlns =" http://maven.apache.org/POM/4.0.0" xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation=" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
3+ <modelVersion >4.0.0</modelVersion >
4+ <groupId >com.javahelps</groupId >
5+ <artifactId >PCAP-Parser</artifactId >
6+ <version >0.0.1-SNAPSHOT</version >
7+
8+ <properties >
9+ <maven .compiler.source>1.8</maven .compiler.source>
10+ <maven .compiler.target>1.8</maven .compiler.target>
11+ </properties >
12+
13+ <dependencies >
14+ <dependency >
15+ <groupId >io.pkts</groupId >
16+ <artifactId >pkts-core</artifactId >
17+ <version >3.0.0</version >
18+ <type >jar</type >
19+ </dependency >
20+
21+ <dependency >
22+ <groupId >io.pkts</groupId >
23+ <artifactId >pkts-streams</artifactId >
24+ <version >3.0.0</version >
25+ <type >jar</type >
26+ </dependency >
27+ </dependencies >
28+ </project >
Original file line number Diff line number Diff line change 1+ package com .javahelps .pcapparser ;
2+
3+ import io .pkts .PacketHandler ;
4+ import io .pkts .Pcap ;
5+ import io .pkts .buffer .Buffer ;
6+ import io .pkts .packet .Packet ;
7+ import io .pkts .packet .TCPPacket ;
8+ import io .pkts .packet .UDPPacket ;
9+ import io .pkts .protocol .Protocol ;
10+
11+ import java .io .IOException ;
12+
13+ public class Main {
14+
15+ public static void main (String [] args ) throws IOException {
16+
17+ final Pcap pcap = Pcap .openStream ("tcpdump.pcap" );
18+
19+ pcap .loop (new PacketHandler () {
20+ @ Override
21+ public boolean nextPacket (Packet packet ) throws IOException {
22+
23+ if (packet .hasProtocol (Protocol .TCP )) {
24+
25+ TCPPacket tcpPacket = (TCPPacket ) packet .getPacket (Protocol .TCP );
26+ Buffer buffer = tcpPacket .getPayload ();
27+ if (buffer != null ) {
28+ System .out .println ("TCP: " + buffer );
29+ }
30+ } else if (packet .hasProtocol (Protocol .UDP )) {
31+
32+ UDPPacket udpPacket = (UDPPacket ) packet .getPacket (Protocol .UDP );
33+ Buffer buffer = udpPacket .getPayload ();
34+ if (buffer != null ) {
35+ System .out .println ("UDP: " + buffer );
36+ }
37+ }
38+ return true ;
39+ }
40+ });
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments