jpcap的问题求助
道隐凤凰鸣 2013-04-16 10:39:35 代码如下:
package test;
import jpcap.*;
import jpcap.packet.ARPPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;
import jpcap.packet.UDPPacket;
public class CapturePacket implements PacketReceiver{
final NetworkInterface[] netintface;
JpcapCaptor jcap;
public CapturePacket(){
netintface=JpcapCaptor.getDeviceList();
}
public static void main(String args[]){
CapturePacket cp=new CapturePacket();
cp.packetCapture();
}
public void packetCapture(){
try {
jcap=JpcapCaptor.openDevice(netintface[1], 1024,false, 1000);
System.out.println(netintface[1]);
jcap.loopPacket(-1, this);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
@Override
public void receivePacket(Packet packet) {
// TODO Auto-generated method stub
if(packet instanceof ARPPacket){
System.out.println("ARP");
}else
if(packet instanceof TCPPacket){
System.out.println("TCP");
}else
if(packet instanceof UDPPacket){
System.out.println("UDP");
}else {
System.out.println("Other");
}
}
}
运行结果如下:
jpcap.NetworkInterface@18e2b22
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
Other
我抓的包应该是tcp或者udp包的一种,但为什么抓的包无法判断的更具体