ICMPdump.java
资源名称:ICMPdump.rar [点击查看]
上传用户:luaite
上传日期:2022-08-06
资源大小:1k
文件大小:2k
源码类别:
网络编程
开发平台:
Java
- import jpcap.*;
- import java.net.*;
- public class ICMPdump implements JpcapHandler
- {
- public void handlePacket(Packet packet){
- System.out.println(packet);
- if (packet instanceof ICMPPacket) {
- System.out.println("协议类型:icmpPacket");
- ICMPPacket icmpPacket = (ICMPPacket) packet;
- /*System.out.println("Id=" + icmpPacket.id +":" );
- System.out.println("Type=" + icmpPacket.type);
- System.out.println("Code=" + icmpPacket.code);
- System.out.println("data=" + icmpPacket.data);*/
- String srchost=String.valueOf(icmpPacket.getSourceAddress());
- String dstHost = String.valueOf(icmpPacket.getDestinationAddress());
- // System.out.println("icmpPacket sourceaddress"+icmpPacket.sourceaddress);
- // System.out.println("icmpPacket destinationaddress"+icmpPacket.destinationaddress);
- System.out.println("icmpPacket type" + icmpPacket.type);
- System.out.println("icmpPacket code" + icmpPacket.code);
- System.out.println("icmpPacket checksum" + icmpPacket.checksum);
- System.out.println("");
- System.out.println("ip header" + icmpPacket.header);
- System.out.println("icmpPacket data" + icmpPacket.data);
- }
- }
- public static void main(String[] args) throws java.io.IOException{
- String[] devices = Jpcap.getDeviceList();
- System.out.println("Start capturing on "+devices[0]);
- String deviceName = devices[0];
- Jpcap jpcap = Jpcap.openDevice(deviceName, 1000, false, 20);
- jpcap.loopPacket(-1, new ICMPdump());
- }
- }