ARPdump.java
资源名称:ARPdump.rar [点击查看]
上传用户:jxm8507
上传日期:2022-08-06
资源大小:1k
文件大小:1k
源码类别:
网络编程
开发平台:
Java
- package bysj;
- import jpcap.*;
- import java.net.*;
- public class ARPdump implements JpcapHandler
- {
- public void handlePacket(Packet packet){
- Packet p = packet;
- try {
- if (p instanceof ARPPacket) {
- ARPPacket arpp = (ARPPacket) p;
- System.out.println(arpp.hardtype);
- System.out.println(arpp.prototype);
- System.out.println(arpp.hlen);
- System.out.println(arpp.plen);
- System.out.println(arpp.operation);
- System.out.println("ARP packet From:" + arpp.getSenderHardwareAddress());
- System.out.println("ARP packet To:" + arpp.getTargetHardwareAddress());
- System.out.println("From:" + arpp.getSenderProtocolAddress());
- System.out.println("To:" + arpp.getTargetProtocolAddress());
- //System.out.println(p.toString());
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- 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 ARPdump());
- }
- }