• 大小: 143KB
    文件类型: .zip
    金币: 2
    下载: 1 次
    发布日期: 2021-05-16
  • 语言: Java
  • 标签: 图形  网络  

资源简介

JpcapDumper-0.3-src.zip java抓取网络数据包

资源截图

代码片段和文件信息

/*
 * Created on Apr 4 2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package jdumper;

import java.io.File;
import java.util.Vector;

import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

import jdumper.stat.JDStatisticsTaker;
import jdumper.ui.JDCaptureDialog;
import jdumper.ui.JDContinuousStatframe;
import jdumper.ui.JDCumlativeStatframe;
import jdumper.ui.JDframe;
import jdumper.ui.JDStatframe;

import jpcap.JpcapCaptor;
import jpcap.PacketReceiver;
import jpcap.JpcapWriter;
import jpcap.packet.Packet;

/**
 * @author kfujii
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class JDCaptor {
long MAX_PACKETS_HOLD=10000;

Vector packets = new Vector();

JpcapCaptor jpcap=null;

boolean isLiveCapture;
boolean isSaved = false;

JDframe frame;

public void setJDframe(JDframe frame){
this.frame=frame;
}

public Vector getPackets(){
return packets;
}


public void capturePacketsFromDevice() {
if(jpcap!=null)
jpcap.close();
jpcap = JDCaptureDialog.getJpcap(frame);
clear();

if (jpcap != null) {
isLiveCapture = true;
frame.disableCapture();

startCaptureThread();
}
}

public void loadPacketsFromFile() {
isLiveCapture = false;
clear();

int ret = JpcapDumper.chooser.showOpenDialog(frame);
if (ret == JFileChooser.APPROVE_OPTION) {
String path = JpcapDumper.chooser.getSelectedFile().getPath();
String filename = JpcapDumper.chooser.getSelectedFile().getName();

try {
if(jpcap!=null){
jpcap.close();
}
jpcap = JpcapCaptor.openFile(path);
} catch (java.io.IOException e) {
JOptionPane.showMessageDialog(
frame
“Can‘t open file: “ + path);
e.printStackTrace();
return;
}

frame.disableCapture();

startCaptureThread();
}
}

private void clear(){
packets.clear();
frame.clear();

for(int i=0;iames.size();i++)
((JDStatframe)sframes.get(i)).clear();
}

public void saveToFile() {
if (packets == null)
return;

int ret = JpcapDumper.chooser.showSaveDialog(frame);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = JpcapDumper.chooser.getSelectedFile();

if (file.exists()) {
if (JOptionPane
.showConfirmDialog(
frame
“Overwrite “ + file.getName() + “?“
“Overwrite?“
JOptionPane.YES_NO_OPTION)
== JOptionPane.NO_OPTION) {
return;
}
}

try {
//System.out.println(“link:“+info.linktype);
//System.out.println(lastJpcap);
JpcapWriter writer = JpcapWriter.openDumpFile(jpcapfile.getPath());

for (int i = 0; i < packets.size(); i++) {
writer.writePacket((Packet) packets.elementAt(i));
}

writer.close();
isSaved = true;
//JOptionPane.sh

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2007-02-20 16:08  doc\
     目录           0  2007-02-20 16:08  src\
     目录           0  2007-02-20 16:08  src\image\
     目录           0  2007-02-20 16:08  src\jdumper\
     目录           0  2007-02-20 16:08  src\jdumper\analyzer\
     目录           0  2007-02-20 16:08  src\jdumper\stat\
     目录           0  2007-02-20 16:08  src\jdumper\ui\
     目录           0  2007-02-20 16:08  src\jdumper\ui\graph\
     文件       26432  2006-01-09 13:31  COPYING
     文件          56  2006-01-09 13:31  JpcapDumper.MF
     文件         180  2007-02-20 16:32  JpcapDumper.property
     文件         603  2007-02-20 16:38  build.xml
     文件        3804  2006-01-09 22:41  doc\document.html
     文件        5260  2006-01-09 22:41  doc\donation.html
     文件        5232  2006-01-09 22:41  doc\download.html
     文件        3799  2006-01-09 22:41  doc\faq.html
     文件        6445  2006-01-09 22:41  doc\index.html
     文件        5032  2006-01-09 22:41  doc\install.html
     文件        4683  2006-01-09 22:41  doc\links.html
     文件       87247  2003-04-08 17:52  doc\screenshot.PNG
     文件        3981  2006-01-09 22:41  doc\screenshot.html
     文件        1021  2003-04-04 12:07  src\image\capture.gif
     文件         986  2003-04-04 12:07  src\image\nic.gif
     文件         154  2003-04-04 12:07  src\image\open.gif
     文件         148  2003-04-04 12:07  src\image\save.gif
     文件        1001  2003-04-04 12:07  src\image\stopcap.gif
     文件        5268  2006-01-09 13:31  src\jdumper\JDCaptor.java
     文件        1477  2003-04-04 18:58  src\jdumper\JDPacketAnalyzerLoader.java
     文件        1019  2003-04-04 18:58  src\jdumper\JDStatisticsTakerLoader.java
     文件        1750  2006-01-09 13:31  src\jdumper\JpcapDumper.java
     文件        2436  2006-01-09 13:31  src\jdumper\analyzer\ARPAnalyzer.java
............此处省略35个文件信息

评论

共有 条评论