• 大小: 5.05MB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2023-11-02
  • 语言: Java
  • 标签: JPCAP  

资源简介

使用JAVA库JPCAP来在传输层构造TCP数据包发送,并在网络层捕获数据包!

资源截图

代码片段和文件信息

/*
 * 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

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    I.A....       603  2007-02-20 16:38  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\build.xml

    I.A....     26432  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\COPYING

    I.A....      3804  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\document.html

    I.A....      5260  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\donation.html

    I.A....      5232  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\download.html

    I.A....      3799  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\faq.html

    I.A....      6445  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\index.html

    I.A....      5032  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\install.html

    I.A....      4683  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\links.html

    I.A....      3981  2006-01-09 22:41  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\screenshot.html

    I.A....     87247  2003-04-08 17:52  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\doc\screenshot.PNG

    I.A....        56  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\JpcapDumper.MF

    I.A....       180  2007-02-20 16:32  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\JpcapDumper.property

    I.A....      1021  2003-04-04 12:07  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\capture.gif

    I.A....       986  2003-04-04 12:07  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\nic.gif

    I.A....       154  2003-04-04 12:07  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\open.gif

    I.A....       148  2003-04-04 12:07  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\save.gif

    I.A....      1001  2003-04-04 12:07  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\stopcap.gif

    I.A.SH.      9216  2007-07-26 12:47  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\image\Thumbs.db

    I.A....      2436  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\ARPAnalyzer.java

    I.A....      1194  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\EthernetAnalyzer.java

    I.A....       719  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\FTPAnalyzer.java

    I.A....      1600  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\HTTPAnalyzer.java

    I.A....      2634  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\ICMPAnalyzer.java

    I.A....      2743  2007-02-20 16:28  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\IPv4Analyzer.java

    I.A....      1803  2007-02-20 16:29  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\IPv6Analyzer.java

    I.A....       616  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\JDPacketAnalyzer.java

    I.A....      1145  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\PacketAnalyzer.java

    I.A....       655  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\POP3Analyzer.java

    I.A....       653  2006-01-09 13:31  Java抓包必备\JpacapDumper\JpcapDumper-0.3-src\src\jdumper\analyzer\SMTPAnalyzer.java

............此处省略535个文件信息

评论

共有 条评论