用JAVA与JPCAP编写一个抓IPV6的包,遇到的问题是,可以抓到IPV4的包却不能抓到IPV6的包!!!!请教..!!谢谢~~~如果过滤条件写为captor.setFilter("ip",true)则可以抓到包,如下:
init:
deps-jar:
compile-single:
run-single:
1225868205:254358 /222.201.184.128->/222.201.184.255 protocol(17) priority(0) hop(128) offset(0) ident(18303) UDP 137 > 137
1225868205:465121 /222.201.135.222->/222.201.135.255 protocol(17) priority(0) hop(128) offset(0) ident(55406) UDP 137 > 137
1225868205:717466 /222.201.135.150->/255.255.255.255 protocol(17) priority(0) hop(128) offset(0) ident(58334) UDP 2544 > 1900
1225868206:4423 /222.201.184.128->/222.201.184.255 protocol(17) priority(0) hop(128) offset(0) ident(18340) UDP 137 > 137
1225868206:214674 /222.201.135.222->/222.201.135.255 protocol(17) priority(0) hop(128) offset(0) ident(55663) UDP 137 > 137
1225868206:266481 /222.201.183.67->/222.201.130.30 protocol(17) priority(0) hop(128) offset(0) ident(3543) UDP 64507 > 53
1225868206:267080 /222.201.130.30->/222.201.183.67 protocol(17) priority(0) hop(62) offset(0) ident(27697) UDP 53 > 64507
1225868206:270090 /222.201.183.67->/222.201.130.30 protocol(17) priority(0) hop(128) offset(0) ident(3544) UDP 58951 > 53
1225868206:272209 /222.201.130.30->/222.201.183.67 protocol(17) priority(0) hop(62) offset(0) ident(27698) UDP 53 > 58951
1225868206:274054 /222.201.183.67->/219.232.253.45 protocol(6) priority(0) hop(128) offset(0) ident(3545) TCP 1337 > 80 seq(472211195) win(65535) S
生成成功(总时间:2 秒)如果过滤条件设为captor.setFilter("ip6",true),则出现下面情况:
init:
deps-jar:
Compiling 1 source file to E:\java\CapturePacket\build\classes
compile:
run:
1225868315:122401
1225868315:157092
1225868316:125073
1225868316:159822
1225868317:127987
1225868317:162702
1225868318:130917
1225868318:165632
1225868319:901329
1225868319:901886
生成成功(总时间:12 秒)
____________________________________________________所有程序如下:package capturepacket;
****main*****
public class Main {
public static void main(String[] args) {
// getd.ShowNeworkInterfaceDevices();
GetPacket getp=new GetPacket();
try {
getp.getMyPacket();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
************
***class GetDevices***package capturepacket;
import jpcap.*;public class GetDevices {
/** Creates a new instance of GetDevices */
public GetDevices() {
}
public static void ShowNeworkInterfaceDevices()
{
//获得网卡设备的实例列表
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
//循环输出全部网卡设备对象相应的信息
for (int i = 0; i < devices.length; i++)
{ //设备号 ,网卡名,网卡描述
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");
//网卡所处数据链路层的名称与其描述
System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
//网卡MAC地址
System.out.print(" MAC address:");
for (byte b : devices[i].mac_address) //转化为十六进制的字串符表示
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println(); //print out its IP address, subnet mask and broadcast address
//输出网卡IP地址 IPV4 IPV6 子网地址 扩播地址
for (NetworkInterfaceAddress a : devices[i].addresses)
System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);}
}
}
*****************
*****class GetPacket******package capturepacket;
import jpcap.JpcapCaptor.*;
import jpcap.*;public class GetPacket {
/** Creates a new instance of GetPacket */
public GetPacket() {
}
public static void getMyPacket() throws Exception {
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
int index=1;//抓自己机子的包
JpcapCaptor captor = JpcapCaptor.openDevice(devices[index],65535, false, 2000);
captor.setFilter("ip6",true);//过滤条件!!
captor.loopPacket(10,new Receiver());
}
}
class Receiver implements PacketReceiver
{
/*实例receivePacket方法*/
public void receivePacket(Packet p)
{
System.out.println(p);
}
}
********************
init:
deps-jar:
compile-single:
run-single:
1225868205:254358 /222.201.184.128->/222.201.184.255 protocol(17) priority(0) hop(128) offset(0) ident(18303) UDP 137 > 137
1225868205:465121 /222.201.135.222->/222.201.135.255 protocol(17) priority(0) hop(128) offset(0) ident(55406) UDP 137 > 137
1225868205:717466 /222.201.135.150->/255.255.255.255 protocol(17) priority(0) hop(128) offset(0) ident(58334) UDP 2544 > 1900
1225868206:4423 /222.201.184.128->/222.201.184.255 protocol(17) priority(0) hop(128) offset(0) ident(18340) UDP 137 > 137
1225868206:214674 /222.201.135.222->/222.201.135.255 protocol(17) priority(0) hop(128) offset(0) ident(55663) UDP 137 > 137
1225868206:266481 /222.201.183.67->/222.201.130.30 protocol(17) priority(0) hop(128) offset(0) ident(3543) UDP 64507 > 53
1225868206:267080 /222.201.130.30->/222.201.183.67 protocol(17) priority(0) hop(62) offset(0) ident(27697) UDP 53 > 64507
1225868206:270090 /222.201.183.67->/222.201.130.30 protocol(17) priority(0) hop(128) offset(0) ident(3544) UDP 58951 > 53
1225868206:272209 /222.201.130.30->/222.201.183.67 protocol(17) priority(0) hop(62) offset(0) ident(27698) UDP 53 > 58951
1225868206:274054 /222.201.183.67->/219.232.253.45 protocol(6) priority(0) hop(128) offset(0) ident(3545) TCP 1337 > 80 seq(472211195) win(65535) S
生成成功(总时间:2 秒)如果过滤条件设为captor.setFilter("ip6",true),则出现下面情况:
init:
deps-jar:
Compiling 1 source file to E:\java\CapturePacket\build\classes
compile:
run:
1225868315:122401
1225868315:157092
1225868316:125073
1225868316:159822
1225868317:127987
1225868317:162702
1225868318:130917
1225868318:165632
1225868319:901329
1225868319:901886
生成成功(总时间:12 秒)
____________________________________________________所有程序如下:package capturepacket;
****main*****
public class Main {
public static void main(String[] args) {
// getd.ShowNeworkInterfaceDevices();
GetPacket getp=new GetPacket();
try {
getp.getMyPacket();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
************
***class GetDevices***package capturepacket;
import jpcap.*;public class GetDevices {
/** Creates a new instance of GetDevices */
public GetDevices() {
}
public static void ShowNeworkInterfaceDevices()
{
//获得网卡设备的实例列表
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
//循环输出全部网卡设备对象相应的信息
for (int i = 0; i < devices.length; i++)
{ //设备号 ,网卡名,网卡描述
System.out.println(i+": "+devices[i].name + "(" + devices[i].description+")");
//网卡所处数据链路层的名称与其描述
System.out.println(" datalink: "+devices[i].datalink_name + "(" + devices[i].datalink_description+")");
//网卡MAC地址
System.out.print(" MAC address:");
for (byte b : devices[i].mac_address) //转化为十六进制的字串符表示
System.out.print(Integer.toHexString(b&0xff) + ":");
System.out.println(); //print out its IP address, subnet mask and broadcast address
//输出网卡IP地址 IPV4 IPV6 子网地址 扩播地址
for (NetworkInterfaceAddress a : devices[i].addresses)
System.out.println(" address:"+a.address + " " + a.subnet + " "+ a.broadcast);}
}
}
*****************
*****class GetPacket******package capturepacket;
import jpcap.JpcapCaptor.*;
import jpcap.*;public class GetPacket {
/** Creates a new instance of GetPacket */
public GetPacket() {
}
public static void getMyPacket() throws Exception {
NetworkInterface[] devices = JpcapCaptor.getDeviceList();
int index=1;//抓自己机子的包
JpcapCaptor captor = JpcapCaptor.openDevice(devices[index],65535, false, 2000);
captor.setFilter("ip6",true);//过滤条件!!
captor.loopPacket(10,new Receiver());
}
}
class Receiver implements PacketReceiver
{
/*实例receivePacket方法*/
public void receivePacket(Packet p)
{
System.out.println(p);
}
}
********************
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货