我正在尝试使用我在网上找到的旧教程用 Java 编写数据包嗅探器,但调试时遇到问题。我收到一条错误消息,指出我的类 pktSniffer 没有继承抽象方法。
import jpcap.*;
import jpcap.packet.Packet;
import jpcap.PacketReceiver;
public class pktSniffer implements PacketReceiver {
public void handlePacket(Packet packet){
System.out.println(packet);
}
public static void main(String[] args) throws java.io.IOException{
NetworkInterface[] lists=jpcap.JpcapCaptor.getDeviceList();
System.out.println("\n\t\t***Network Sniffer***\n");
System.out.println("Found the following devices : ");
for(NetworkInterface s: lists)
{
System.out.println("Name: " + s.name +" Description: " + s.description);
}
JpcapCaptor jpcap=JpcapCaptor.openDevice(JpcapCaptor.getDeviceList()[1],1000,false,20);
jpcap.loopPacket(-1,new pktSniffer());
}
}