问题描述
packagem4;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileWriter;importjava.io.IOException;importjava.io.UnsupportedEncodingException;importjpcap.packet.*;importjpcap.*;classTcpdumpimplementsPacketReceiver{publicvoidreceivePacket(Packetpacket){BufferedWriterpw=null;//newBufferedWriter();Filefin=newFile("test.txt");try{pw=newBufferedWriter(newFileWriter(fin,true));}catch(IOExceptione){//TODO自动生成catch块e.printStackTrace();}if(packetinstanceofTCPPacket){TCPPackettcpPacket=(TCPPacket)packet;//if(tcpPacket.dst_port==80){System.out.println("port:"+tcpPacket.dst_port+"seq:"+tcpPacket.sequence);Stringa=newString("port:"+tcpPacket.dst_port+"seq:"+tcpPacket.sequence);Strings;try{s=newString(tcpPacket.data,"UTF-8");//gb2312UTF-8GBK//}catch(UnsupportedEncodingExceptione1){//TODO自动生成catch块//e1.printStackTrace();//}//try{pw.write(a);pw.newLine();pw.write(s);pw.flush();pw.close();}catch(IOExceptione){//TODO自动生成catch块e.printStackTrace();}//}}}}publicclassPacketCapture{publicstaticvoidmain(String[]args)throwsException{NetworkInterface[]devices=JpcapCaptor.getDeviceList();NetworkInterfacedevice=devices[0];JpcapCaptorjpcap=JpcapCaptor.openDevice(device,2000,false,20);jpcap.setFilter("tcp",true);jpcap.loopPacket(-1,newTcpdump());}}
tcpPacket.data返回是gzip压缩数据怎样把数据解压求方法啊
解决方案
解决方案二:
没有人帮忙求救
解决方案三:
在线等求帮忙
解决方案四:
参考zlib函数,使用uncompress(char*dest,int*destLen,char*source,intsourceLen)就可以在内存中对原始报文信息source进行解压缩处理。不知道这是不是你想要的
解决方案五:
继续在线等方法
解决方案六:
试试GZIPInputStream?
解决方案七:
packagem4;importjava.io.BufferedWriter;importjava.io.ByteArrayInputStream;importjava.io.ByteArrayOutputStream;importjava.io.File;importjava.io.FileWriter;importjava.io.IOException;importjava.io.UnsupportedEncodingException;importjava.util.zip.GZIPInputStream;importjpcap.packet.*;importjpcap.*;classTcpdumpimplementsPacketReceiver{publicvoidreceivePacket(Packetpacket){BufferedWriterpw=null;//newBufferedWriter();Filefin=newFile("test.txt");try{pw=newBufferedWriter(newFileWriter(fin,true));}catch(IOExceptione){//TODO自动生成catch块e.printStackTrace();}byte[]buffer1=null;if(packetinstanceofTCPPacket){TCPPackettcpPacket=(TCPPacket)packet;//if(tcpPacket.dst_port==80){buffer1=tcpPacket.data;}ByteArrayOutputStreamout=newByteArrayOutputStream();ByteArrayInputStreamin=newByteArrayInputStream(buffer1);try{GZIPInputStreamgunzip=newGZIPInputStream(in);byte[]buffer=newbyte[256];intn;while((n=gunzip.read(buffer))>=0){out.write(buffer,0,n);}System.out.println(out.toString());}catch(IOExceptione){//TODO自动生成的catch块e.printStackTrace();}}}publicclassPacketCapture{publicstaticvoidmain(String[]args)throwsException{NetworkInterface[]devices=JpcapCaptor.getDeviceList();NetworkInterfacedevice=devices[0];JpcapCaptorjpcap=JpcapCaptor.openDevice(device,2000,false,20);jpcap.setFilter("tcp",true);jpcap.loopPacket(-1,newTcpdump());}}
异常啊为什么有没有人帮我啊
解决方案八:
在线等求高人
解决方案九:
在线等在线等