[Jpcap] Tcpdump.java
류명운
·2016. 8. 30. 20:44
반응형
[Jpcap] Tcpdump.java
import jpcap.*; import jpcap.packet.Packet; class Tcpdump implements PacketReceiver { public void receivePacket(Packet packet) { System.out.println(packet); } public static void main(String[] args) throws Exception { NetworkInterface[] devices = JpcapCaptor.getDeviceList(); if(args.length<1){ System.out.println("usage: java Tcpdump <select a number from the following>"); for (int i = 0; i < devices.length; i++) { System.out.println(i+" :"+devices[i].name + "(" + devices[i].description+")"); System.out.println(" data link:"+devices[i].datalink_name + "(" + devices[i].datalink_description+")"); System.out.print(" MAC address:"); for (byte b : devices[i].mac_address) System.out.print(Integer.toHexString(b&0xff) + ":"); System.out.println(); for (NetworkInterfaceAddress a : devices[i].addresses) System.out.println(" address:"+a.address + " " + a.subnet + " " + a.broadcast); } }else{ JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[Integer.parseInt(args[0])], 2000, false, 20); jpcap.loopPacket(-1, new Tcpdump()); } } }
반응형
'삶의 늪에 들어 가기 전 > 정리중(미정리)' 카테고리의 다른 글
[공개용 SW 개발] 네x버 맞춤법검사기 파싱 테스트 (0) | 2016.08.30 |
---|---|
[Jpcap] ReadDump.java (0) | 2016.08.30 |
[Jpcap] Traceroute.java (0) | 2016.08.30 |
[Jpcap] SendICMP.java (0) | 2016.08.30 |
[Jpcap] SendTCPIPv6.java (0) | 2016.08.30 |