通过JPcap捕获网络TCP数据包,并将解析的信息写入execl文件中

以下代码主要实现功能:

1.利用JPcap捕获指定网卡的所有TCP数据包,并解析出"SRC_MAC","DST_MAC", "SRC_IP", "DST_IP", "GETInfo", "RefererInfo", "HostInfo"等信息。

2. 将这些信息不覆盖的写入到execl文件,并且将每天的数据信息记录在以年月日命名的execl工作表(sheet)中。

 

 

package execl;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;




import jpcap.*;
import jpcap.packet.EthernetPacket;
import jpcap.packet.Packet;
import jpcap.packet.TCPPacket;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;



public class HttpMessageReceive implements PacketReceiver {
	
	public static File file = new File("G:" + File.separator + "Experiment"
			+ File.separator + "HTTP" + File.separator
			+ "DetailHTTPData.xls");
	public static File tempfile = new File("G:" + File.separator + "Experiment"
			+ File.separator + "HTTP" + File.separator + "temp.xls");
	public static String[] HttpInfoStr = {"0","0","0","0","0","0","0","0"};
	public static final String[] HTTPStart = {"GET","POST","OPTIONS"}; 	//HTTP协议有效信息开始的三个标志
	public static final String[] StrLabel = { "TimeOnLine", "SRC_MAC","DST_MAC", "SRC_IP", "DST_IP", "GETInfo", "RefererInfo", "HostInfo" };
		
	public static void main(String[] args) throws Exception {		
		NetworkInterface[] devices = JpcapCaptor.getDeviceList();
		if(args.length<1){
			System.out.println("usage: java Tcpdump