-
大小: 778KB文件类型: .rar金币: 2下载: 1 次发布日期: 2021-08-01
- 语言: Java
- 标签: JavaIP/TCP
资源简介
用Java实现对IP/TCP协议数据包的拦截和分析,得出IP的详细信息。
代码片段和文件信息
import net.sourceforge.jpcap.capture.*;
import net.sourceforge.jpcap.net.*;
import java.util.*;
import java.io.*;
public class CapturePacketTest implements RawPacketListenerPacketListener{
//public Vector CaptureVec = new Vector();
public static FileOutputStream fos = null;
public static void main(String[] args)throws Exception{
// Print copyright info
System.out.println();
System.out.println(“Capture Ethernet packet Ver 0.01 author yanqlv(maomao).“);
System.out.println(“Copyright (c) 2005 yanqlv of Luoyang Normal College all Rights Reserved.“);
System.out.println();
// Determin which capture device to use
PacketCapture pcap = new PacketCapture();
String defaultDevice = pcap.findDevice();
StringTokenizer st1 = new StringTokenizer(defaultDevice“\n“);
String defaultDeviceStr = st1.nextToken();
int default_num = 1;
String[] capDevices = pcap.lookupDevices();
int capdevice_num = capDevices.length;
System.out.println(“There “+ (capdevice_num>1?“are“:“is“) + “ “+ capdevice_num +“ device“+(capdevice_num>1?“s“:““)+“ found!“);
System.out.println(“*****************************************************************************“);
for (int i=0; i
//System.out.println(“*****capture device[“+ i +“]=“+capDevices[i]);
StringTokenizer st = new StringTokenizer(capDevices[i]“\n“);
String capStr = st.nextToken();
String capDesc = st.nextToken();
if( defaultDeviceStr.equals(capStr) ) default_num = i+1;
System.out.println( “[“ + (i+1) + “] “ + capStr + “\n(“ + capDesc + “)“);
}
System.out.println(“*****************************************************************************“);
System.out.println(“(default to use “+ default_num +“)“);
int selectn = 1;
if(capdevice_num > 1 ){
System.out.print(“Please select [“);
for(int i=0; i
System.out.print(i+1);
if(i!=capdevice_num-1) System.out.print(“ or “);
}
System.out.print(“]:“);
String readstr = new DataInputStream(System.in).readLine();
selectn = Integer.parseInt( new String( readstr ) );
}
//System.out.println(“selectn=“+selectn);
// Want to save capture result to file
fos = new FileOutputStream(“capture.txt“);
// Begin capture
pcap.open( (new StringTokenizer(capDevices[selectn-1]“\n“)).nextToken()true );
CapturePacketTe
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 298 2008-03-11 10:47 snii\.classpath
文件 380 2007-06-29 11:49 snii\.project
文件 0 2008-03-11 10:49 snii\capture.txt
文件 4463 2017-12-16 18:27 snii\CapturePacketTest.class
文件 4516 2007-06-29 11:50 snii\CapturePacketTest.java
文件 76510 2004-10-01 17:45 snii\jpcap.dll
文件 71 2004-09-29 15:03 snii\net.sourceforge.jpcap-0.01.16\me
文件 261 2004-03-16 19:57 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\.cvsignore
文件 708 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureConfigurationException.class
文件 1176 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureConfigurationException.java
文件 708 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceInvalidException.class
文件 1176 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceInvalidException.java
文件 705 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceLookupException.class
文件 1056 2002-02-18 14:51 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceLookupException.java
文件 711 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceNotFoundException.class
文件 1088 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceNotFoundException.java
文件 699 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceOpenException.class
文件 1074 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureDeviceOpenException.java
文件 693 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureFileOpenException.class
文件 1046 2001-12-30 16:07 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureFileOpenException.java
文件 687 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CapturePacketException.class
文件 1059 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CapturePacketException.java
文件 1042 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureStatistics.class
文件 1642 2001-05-17 14:13 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureStatistics.java
文件 1113 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureTest.class
文件 3611 2001-05-22 20:55 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CaptureTest.java
文件 1357 2004-09-29 14:55 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CVS\Entries
文件 39 2004-02-24 22:48 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CVS\Repository
文件 60 2004-02-24 22:48 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\CVS\Root
文件 687 2017-12-16 18:27 snii\net.sourceforge.jpcap-0.01.16\net\sourceforge\jpcap\capture\InvalidFilterException.class
............此处省略315个文件信息
- 上一篇:java小程序的案例小程序
- 下一篇:纯java写的library的图书管理系统
评论
共有 条评论