本文介绍了原始以太网的Java库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个Java库,该库将使我能够访问原始的以太网帧,以读取和发送它们。我的最终目标是创建一个BACnet以太网网络扫描仪。

I'm looking for a Java library that will give me access to raw Ethernet frames, both for reading and sending them. My end goal is to create a BACnet Ethernet network scanner.

请注意,我不是在寻找TCP\IP。

Please, Note, I'm not looking for TCP\IP.

任何人都知道好的

推荐答案

也许可以提供帮助。请注意,有一个同名的Sourceforge项目,但似乎不是同一项目。

Maybe Jpcap can help. Notice that there's a Sourceforge project with the same name, but it doesn't seem to be the same project.

这里有一些示例代码(来自库的教程)使用通过Jpcap发送TCP数据包和以太网帧:

Here's some sample code (from the library's tutorial) that uses Jpcap to send a TCP packet and an Ethernet frame:

编辑:该示例代码确实创建了 TCPPacket ,但是您可以改为创建常规的 Packet

The sample code does create a TCPPacket, but you may create a regular Packet instead.

//open a network interface to send a packet to
JpcapSender sender=JpcapSender.openDevice(devices[index]);

//create a TCP packet with specified port numbers, flags, and other parameters
TCPPacket p=new TCPPacket(12,34,56,78,false,false,false,false,true,true,true,true,10,10);

//specify IPv4 header parameters
p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,1010101,100,IPPacket.IPPROTO_TCP,
  InetAddress.getByName("www.microsoft.com"),InetAddress.getByName("www.google.com"));

//set the data field of the packet
p.data=("data").getBytes();

//create an Ethernet packet (frame)
EthernetPacket ether=new EthernetPacket();
//set frame type as IP
ether.frametype=EthernetPacket.ETHERTYPE_IP;
//set source and destination MAC addresses
ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5};
ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10};

//set the datalink frame of the packet p as ether
p.datalink=ether;

//send the packet p
sender.sendPacket(p);

sender.close();

这篇关于原始以太网的Java库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-09 03:45