基于JPCAP采集流量的
import java.io.*;import jpcap.*;
import java.util.*;
import java.text.*;
import jpcap.packet.*;
public class JpcapTip implements JpcapHandler {//JpcapHandler 出错
static int j=0;
static long p=0,q=0;
IPPacket ip;
String s,s1;
Long s2;
static long time11,time12;
public void handlePacket(Packet packet){
if(packet instanceof IPPacket)
{
System.out.println("ok");
ip=(IPPacket)packet;
if(j<2000)
{
try {
RandomAccessFile rf = new RandomAccessFile("packet3.txt", "rw");
rf.seek(rf.length());
rf.writeBytes(ip.src_ip+"\t"+ip.dst_ip+"\t"+ip.protocol+"\t"+
ip.length+"\t"+ip.version+"\t"+ip.ident+"\t"+
ip.rsv_frag+"\t"+ip.offset+"\t"+ip.hop_limit+"\t"+
ip.rsv_tos+"\r\n");
rf.close();
}
catch (Exception e) {
e.printStackTrace();
}
j++;
}
else
{
time12=System.currentTimeMillis();
System.out.println(""+time12+"-"+time11+"="+(time12-time11)+"\ncapture count:"+j);
System.exit(0);
}
}
}
public static void main(String[] args) throws java.io.IOException
{
String[] devices = Jpcap.getDeviceList();//Jpcap出错
String deviceName = devices[0];
Jpcap jpcap = Jpcap.openDevice(deviceName, 1028, true, 100);
//即将打开的设备名//
//从设备上一次读取的最大字节数//
//说明是否将设备设为混杂模式的Boolean值//
//超时值//
time11=System.currentTimeMillis();
while(true)
{
jpcap.loopPacket(10, new JpcapTip());
}
}
} 这里JpcapHandler,Jpcap出错!
是怎么回事?请高手帮忙 --------------------编程问答-------------------- 同楼主,我的也是解析不到JpcapHandler
补充:Java , Eclipse