使用WinPcap捕获数据包 [英] capture of packet using WinPcap

查看:362
本文介绍了使用WinPcap捕获数据包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了WinPcap来捕获数据包.并且我还复制了一些文件.dll扩展名并粘贴到JDK中.但是我的第一行仍然存在一些问题,即在"import jpcap.JpcapCaptor"中,我不知道为什么这正在发生...虽然我将其(jpcap.dll)复制并粘贴到了我的JDK中... plz帮助....并提供了一些有关如何捕获数据包的建议...我的平台是netbeans 7.0

I have installed WinPcap for capturing packet.. and i also copied some files .dll extension and paste in JDK.. but still some problems are in my first line i.e in "" import jpcap.JpcapCaptor"" i donot know why this is happening... though i copied and paste it (jpcap.dll) in my JDK... plz help.... and give some advice how to capture packets... my platform is netbeans 7.0

import jpcap.JpcapCaptor; 
import jpcap.NetworkInterface; 
import jpcap.NetworkInterfaceAddress; 
import java.io.IOException; 
import java.util.Scanner; 
import javax.swing.JFrame; 

public class PacketAnalyser { static String text="";  
public String capture(){	   
	try { 
		captor=JpcapCaptor.openDevice(devices[index], 65535, true, 20); 
		long[] packs = new long[20]; 
		int tcp = 0; 
		int udp = 1; 
		for(int j = 0;j<10;j++){ 
		long count1 = 0; 
		long count2 = 0; 
		captor.setFilter("tcp and ip", true); 
		for(int i=0;i<10;i++){ 
			  
		text1=text1+captor.getPacket()+"\n"; 
		if(captor.getPacket()!=null){count1++;}} 
		text1=text1+captor.dropped_packets + " packets dropped by kernel\n"; 
		text1=text1+count1+"\n"  ; 
		captor.setFilter("udp and ip", true); 
		for(int i=0;i<10;i++){ 
		text1=text1+captor.getPacket()+"\n"  ; 
		if(captor.getPacket()!=null){count2++;} 
		} 
		text1=text1+captor.dropped_packets + " packets dropped by kernel\n"; 
		text1=text1+count2+"\n"; 
		packs[tcp]=count1; 
		packs[udp]=count2; 
		tcp+=2; 
		udp+=2; 
		} 
		
	captor.close(); 
	return text1; }}

推荐答案

如果您的编译器或IDE告诉您它不喜欢您的第一个import语句,则原因是您拥有没有为编译器正确包含jpcap jar.
If your compiler or IDE is telling you that it doesn''t like your very first import statement then the reason is that you have not included the jpcap jar(s) correctly for the compiler.


这篇关于使用WinPcap捕获数据包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆