本文整理汇总了Java中org.jnetpcap.protocol.lan.Ethernet类的典型用法代码示例。如果您正苦于以下问题:Java Ethernet类的具体用法?Java Ethernet怎么用?Java Ethernet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ethernet类属于org.jnetpcap.protocol.lan包,在下文中一共展示了Ethernet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testScanIpv6File
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Printing to DEV_NULL still causes entire packet structure to be decoded and
* dumped to /dev/null while using every available header found in the packet.
* Good stress test for Ip6 based packets.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testScanIpv6File() throws IOException {
TextFormatter out = new TextFormatter(OUT);
out.setResolveAddresses(false);
int i = 0;
Ethernet eth = new Ethernet();
for (PcapPacket packet : TestUtils.getIterable("tests/test-ipv6.pcap")) {
System.out.println(packet.toDebugString());
if (packet.hasHeader(eth)) {
out.format(eth);
}
out.setFrameIndex(i++);
out.format(packet);
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:26,代码来源:TestIpv6.java
示例2: setPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Set the value of the field packet
* @param packet the new packet to set
*/
public boolean setPacket(final PcapPacket packet) {
boolean unkown = false;
_packet = packet;
eth = packet.getHeader(new Ethernet());
ip = packet.getHeader(new Ip4());
tcp = packet.getHeader(new Tcp());
if (tcp == null) {
udp = packet.getHeader(new Udp());
if (udp == null) {
icmp = packet.getHeader(new Icmp());
if (icmp == null) {
unkown = true;
setProtocol(Protocol.OTHER);
} else {
setProtocol(Protocol.ICMP);
}
} else {
setProtocol(Protocol.UDP);
}
} else {
setProtocol(Protocol.TCP);
}
return !unkown;
}
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:29,代码来源:JNetCapPacketPoint.java
示例3: meetCriteria
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
if (!itemToCheck.hasHeader(Ethernet.ID))
return false;
Ethernet eth = new Ethernet();
eth = itemToCheck.getHeader(eth);
switch (direction)
{
case Incoming:
return Arrays.equals(ownMAC, eth.destination());
case Outgoing:
return Arrays.equals(ownMAC, eth.source());
default:
return false; //doesn't get here
}
}
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:20,代码来源:CriteriaPacketDirection.java
示例4: testJHeaderIsFragmented
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test j header is fragmented.
*/
public void testJHeaderIsFragmented() {
JPacket packet = TestUtils.getPcapPacket(TestUtils.REASEMBLY, 1 - 1);
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
assertFalse(eth.isFragmented());
}
Ip4 ip = new Ip4();
if (packet.hasHeader(ip)) {
assertTrue(ip.isFragmented());
}
Icmp icmp = new Icmp();
if (packet.hasHeader(icmp)) {
assertTrue(ip.isFragmented());
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:23,代码来源:TestTcpIp.java
示例5: dispatchToPcapPacketHandler
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
public <T> long dispatchToPcapPacketHandler(PcapPacketHandler<T> handler,
T user) {
// for (Record record: buffer) {
// handler.nextPacket(record.header, record.packet, user);
// }
final JPcapRecordBuffer.Iterator i = this.iterator();
for (JPcapRecordBuffer.Record record : this) {
// final PcapPacket pkt = new PcapPacket(record.header, record.packet);
packet.transferHeaderAndDataFrom(record.header, record.packet);
packet.scan(Ethernet.ID);
handler.nextPacket(packet, user);
}
return this.getPacketRecordCount();
}
开发者ID:pvenne,项目名称:jgoose,代码行数:19,代码来源:JPcapRecordBuffer.java
示例6: _testScanOnePacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* _test scan one packet.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void _testScanOnePacket() throws IOException {
JPacket packet = new JMemoryPacket(new byte[] {
(byte) 0xa0,
(byte) 0xa1,
(byte) 0xa2,
(byte) 0xa3,
(byte) 0xa4,
(byte) 0xa5,
(byte) 0xb0,
(byte) 0xb1,
(byte) 0xb2,
(byte) 0xb3,
(byte) 0xb4,
(byte) 0xb5,
(byte) 0x00,
(byte) 0x08, });
JScanner scanner = new JScanner();
scanner.scan(packet, Ethernet.ID);
TextFormatter out = new TextFormatter();
out.format(packet);
}
开发者ID:pvenne,项目名称:jgoose,代码行数:32,代码来源:TestJScanner.java
示例7: nextPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
public void nextPacket(PcapHeader pcapHdr, JBuffer jbuf, String user) {
packet.peerHeaderAndData(pcapHdr, jbuf);
scanner.scan(packet, Ethernet.ID);
assertTrue(packet.getPacketWirelen() > 0);
System.out.printf("JHandlerTest::nextPacket() - %s\n", packet.getState()
.toDebugString());
if (packet.hasHeader(ethernet)) {
System.out.println("ethernet.dst=" + ethernet.destination());
}
if (packet.hasHeader(ip4)) {
System.out.println("ip4.ver=" + ip4.version());
}
if (packet.hasHeader(ip6)) {
System.out.println("ip4.ver=" + ip4.version());
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:23,代码来源:JHandlerTest.java
示例8: handle
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* pseudonymizes the packet according to the settings and stored the
*
* @param packet the captured PcapPacket
*/
@Override
public void handle(PcapPacket packet) {
// Determine if the packet is an ethernet packet first.
if (packet.hasHeader(Ethernet.ID)){
_packetModifier.modifyPacket(packet);
_pseudoDumper.dump(packet);
}
else {
// TODO PEF-77: don't send or nullify the packet.
logger.warning("Non-ethernet packet found, packet is left untouched.");
}
}
开发者ID:NCSC-NL,项目名称:PEF,代码行数:18,代码来源:JNetPcapPseudonymizeDumper.java
示例9: creatPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
private JMemoryPacket creatPacket(final InetAddress destIp, final InetAddress sourceIP) {
final int packetSize = 500;
final JMemoryPacket packet = new JMemoryPacket(packetSize);
packet.order(ByteOrder.BIG_ENDIAN);
packet.setUShort(0 + 12, 0x800); // ethernet.type field
packet.scan(Ethernet.ID);
final Ethernet ethernet = packet.getHeader(new Ethernet());
ethernet.destination(destIp.getAddress());
ethernet.source(sourceIP.getAddress());
packet.setUByte(14, 0x04 | 0x05); // ip v4
packet.scan(Ethernet.ID);
// final JPacket sendPacket = new JMemoryPacket(JProtocol.ETHERNET_ID, " 001801bf 6adc0025 4bb7afec 08004500 "
// + " 0041a983 40004006 d69ac0a8 00342f8c " + " ca30c3ef 008f2e80 11f52ea8 4b578018 "
// + " ffffa6ea 00000101 080a152e ef03002a " + " 2c943538 322e3430 204e4f4f 500d0a");
final Ip4 sendPacketIP = packet.getHeader(new Ip4());
// sendPacketIP.destination(destIp.getAddress());
sendPacketIP.type(0x06); //TCP
sendPacketIP.length(packetSize - ethernet.size());
sendPacketIP.ttl(1);
packet.setUByte(46, 0x50); // TCP
packet.scan(Ethernet.ID);
final Tcp sendPacketTcp = packet.getHeader(new Tcp());
sendPacketTcp.destination(80);
sendPacketIP.checksum(sendPacketIP.calculateChecksum());
sendPacketTcp.checksum(sendPacketTcp.calculateChecksum());
final Payload payload = packet.getHeader(new Payload());
payload.setByteArray(1, "Neko".getBytes());
return packet;
}
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:37,代码来源:JNetCapTraceRoute.java
示例10: testDumpJPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test method for {@link org.jnetpcap.PcapDumper#dump(org.jnetpcap.packet.JMemoryPacket)}.
*/
@Test
public void testDumpJPacket() {
JMemoryPacket packet = new JMemoryPacket(Ethernet.ID, data);
dumper.dump(packet);
checkFileSize();
}
开发者ID:pvenne,项目名称:jgoose,代码行数:12,代码来源:TestPcapDumper.java
示例11: testDiameterHeader
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test diameter header.
*/
public void testDiameterHeader() {
Diameter diameter = new Diameter(); // Need an instance so we can check on sub header
// Wireshark packet # 29 (1-based)
PcapPacket packet = TestUtils.getPcapPacket("tests/tc_TC_IDPRE_EXT0140.pcap", 43 - 1);
System.out.println(packet.toHexdump(128, false, false, true));
long map = packet.getState().get64BitHeaderMap(JProtocol.idToGroup(Diameter.ID));
JRegistry.addBindings(Diameter.class);
System.out.println(JRegistry.toDebugString());
System.out.println(packet);
assertEquals(JRegistry.lookupId(Diameter.class), Diameter.ID);
assertTrue(packet.hasHeader(Ethernet.ID));
assertTrue(packet.hasHeader(JProtocol.IP4_ID, 0));
assertTrue(packet.hasHeader(diameter));
System.out.println(diameter.toHexdump());
// Check specific values
assertEquals(1, diameter.getVersion());
assertEquals(364, diameter.getMessageLength());
assertEquals(0x40, diameter.getCommandFlags());
assertEquals(0x132, diameter.getCommandCode());
}
开发者ID:pvenne,项目名称:jgoose,代码行数:31,代码来源:TestDiameter.java
示例12: testIp4FragmentFlagDirectly
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test ip4 fragment flag directly.
*/
public void testIp4FragmentFlagDirectly() {
JPacket packet = TestUtils.getPcapPacket(TestUtils.REASEMBLY, 1 - 1);
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
// System.out.println(eth);
// System.out.printf("flags=%x\n", eth.getState().getFlags());
assertNotSame(JHeader.State.FLAG_HEADER_FRAGMENTED, (eth.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
Ip4 ip = new Ip4();
if (packet.hasHeader(ip)) {
// System.out.println(ip);
// System.out.printf("flags=%x\n", ip.getState().getFlags());
assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (ip.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
Icmp icmp = new Icmp();
if (packet.hasHeader(icmp)) {
// System.out.println(icmp);
// System.out.printf("flags=%x\n", icmp.getState().getFlags());
assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (icmp.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:32,代码来源:TestTcpIp.java
示例13: test1
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test1.
*/
public void test1() {
JMemoryPacket packet = new JMemoryPacket(64);
packet.order(ByteOrder.BIG_ENDIAN);
packet.setUShort(0 + 12, 0x800);
packet.setUByte(14 + 0, 0x45);
System.out.println(packet.toHexdump());
packet.setUByte(14 + 9, 0x11); //UDP
System.out.println(packet.toHexdump());
packet.scan(JProtocol.ETHERNET_ID);
Ethernet eth = packet.getHeader(new Ethernet());
Ip4 ip = packet.getHeader(new Ip4());
Udp udp = packet.getHeader(new Udp());
// udp.transferFrom(getFakeData(1460)); //Generate Random bytes
eth.destination(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 33});
eth.source(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 34});
ip.flags(0);
ip.tos(0);
ip.source(new byte[] {(byte) 192, (byte) 168, 18, (byte) 218});
ip.setByteArray(16, new byte[] {(byte) 192,(byte) 168, 18, (byte) 219});
ip.checksum(0);
System.out.printf("crc=0x%X ip.len=%d\n", Checksum.inChecksum(ip, 0, ip.size()), ip.size());
ip.checksum(Checksum.inChecksum(ip, 0, ip.size()));
System.out.println(packet.getState().toDebugString());
System.out.printf("crc=0x%X\n", Checksum.inChecksum(ip, 0, ip.size()));
JBuffer b = new JBuffer(4);
b.order(ByteOrder.LITTLE_ENDIAN);
b.setUInt(0, 0x14010100);
System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
b.order(ByteOrder.BIG_ENDIAN);
b.setUInt(0, 0x14010100);
System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
}
开发者ID:pvenne,项目名称:jgoose,代码行数:42,代码来源:Bug2878768_jmemory_packet_int.java
示例14: testPrintEachHeaderGradually
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test print each header gradually.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testPrintEachHeaderGradually() throws IOException {
final String data =
"" + "00 0c 41 76 33 05 00 03 6b f7 12 0f 08 00 45 00"
+ "00 7c 6f f7 40 00 fa 11 f8 8f 41 20 01 41 c0 a8"
+ "14 e0 00 35 c0 66 00 68 60 f0 b4 16 85 83 00 01"
+ "00 00 00 01 00 00 0a 6e 6d 72 66 6c 69 73 6d 73"
+ "31 04 69 61 67 72 03 6e 65 74 00 00 01 00 01 c0"
+ "17 00 06 00 01 00 00 2a 30 00 2f 05 70 64 6e 73"
+ "31 08 75 6c 74 72 61 64 6e 73 c0 1c 07 6b 67 72"
+ "61 75 65 72 c0 17 77 bf dd f5 00 00 2a 30 00 00"
+ "0e 10 00 27 8d 00 00 01 51 80" + "";
final JPacket packet = new JMemoryPacket(JProtocol.ETHERNET_ID, data);
// final String TEMP_CAP = "tests/temp.pcap";
// final File TEMP_CAP_FILE = new File(TEMP_CAP);
// if (TEMP_CAP_FILE.exists()) {
// TEMP_CAP_FILE.delete();
// }
// FormatUtils.createPcapFile(TEMP_CAP, data);
// System.out.println(packet);
System.out.println(packet.getHeader(new Ethernet()));
System.out.println(packet.getHeader(new Ip4()));
System.out.println(packet.getHeader(new Udp()));
System.out.println(packet.getState().toDebugString());
}
开发者ID:pvenne,项目名称:jgoose,代码行数:35,代码来源:Bug2818101_RtpHeaderLength_Invalid.java
示例15: testPeerToJBuffer
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test peer to j buffer.
*/
public void testPeerToJBuffer() {
assertNotNull(VariousInMemoryPackets.PACKET_1);
JPacket packet = new JMemoryPacket(VariousInMemoryPackets.PACKET_1);
packet.scan(Ethernet.ID);
System.out.println(packet);
}
开发者ID:pvenne,项目名称:jgoose,代码行数:11,代码来源:TestPeering.java
示例16: testHttpFormattingWithResolveAddressDisabled
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test http formatting with resolve address disabled.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testHttpFormattingWithResolveAddressDisabled() throws IOException {
JFormatter out = new TextFormatter(OUT);
out.setResolveAddresses(false);
PcapPacket packet = TestUtils.getPcapPacket("tests/test-http-jpeg.pcap", 5);
Ip4 ip = new Ip4();
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
out.format(eth);
}
if (packet.hasHeader(ip)) {
out.format(ip);
out.format(ip);
}
out.format(packet);
Html html = new Html();
assertTrue("html header not found", packet.hasHeader(html));
System.out.printf("link related tags=%s\n", Arrays.asList(html.links())
.toString());
// if (true && packet.hasHeader(http)) {
//
// for (String e : http.fieldArray()) {
// System.out.println(e);
// }
// }
}
开发者ID:pvenne,项目名称:jgoose,代码行数:37,代码来源:TestHttp.java
示例17: testHttpFormattingWithResolveAddressEnabled
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test http formatting with resolve address enabled.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testHttpFormattingWithResolveAddressEnabled() throws IOException {
JLogger.getLogger(JConfig.class).setLevel(Level.FINE);
JLogger.getLogger(Resolver.class.getPackage()).setLevel(Level.FINER);
JFormatter out = new TextFormatter(OUT);
out.setResolveAddresses(true);
PcapPacket packet = TestUtils.getPcapPacket("tests/test-http-jpeg.pcap", 5);
Ip4 ip = new Ip4();
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
out.format(eth);
}
if (packet.hasHeader(ip)) {
// out.format(ip);
out.format(ip);
System.out.println();
}
// out.format(packet);
// if (true && packet.hasHeader(http)) {
// Map<String, Http.Entry> map = http.headerFields();
//
// for (Entry e : map.values()) {
// System.out.println(e.toString());
// }
// }
JRegistry.shutdown();
}
开发者ID:pvenne,项目名称:jgoose,代码行数:40,代码来源:TestHttp.java
示例18: testIterable
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
public void testIterable() {
JPacket packet =
new JMemoryPacket(Ethernet.ID, VariousInMemoryPackets.PACKET_2);
for (JHeader header : packet) {
System.out.println(header);
}
System.out.println(packet.getState().toDebugString());
for (JHeaderChecksum crc : packet.filterByType(JHeaderChecksum.class)) {
crc.recalculateChecksum();
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:TestJPacketIterator.java
示例19: testCoreProtocolRegistrationByName
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test core protocol registration by name.
*
* @throws UnregisteredHeaderException
* the unregistered header exception
*/
public void testCoreProtocolRegistrationByName()
throws UnregisteredHeaderException {
assertEquals(JProtocol.ETHERNET.toString(), Ethernet.ID,
JRegistry.lookupId(Ethernet.class));
assertEquals(JProtocol.IP4.toString(), JProtocol.IP4_ID,
JRegistry.lookupId(Ip4.class));
assertEquals(JProtocol.IP6.toString(), Ip6.ID,
JRegistry.lookupId(Ip6.class));
}
开发者ID:pvenne,项目名称:jgoose,代码行数:17,代码来源:TestJRegistry.java
示例20: testSendPacketUsingJBuffer
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test send packet using j buffer.
*
* @throws UnknownHostException
* the unknown host exception
*/
public void testSendPacketUsingJBuffer() throws UnknownHostException {
JPacket packet =
new JMemoryPacket(JProtocol.ETHERNET_ID,
"0016b6c13cb10021 5db0456c08004500 "
+ "00340e8e40008006 9c54c0a80165d822 "
+ "b5b1c1cf005020ce 4303000000008002 "
+ "2000d94300000204 05b4010303020101 " + "0402");
InetAddress dst = InetAddress.getByName("201.1.1.1");
InetAddress src = InetAddress.getByName("192.168.1.1");
Ip4 ip = packet.getHeader(new Ip4());
Tcp tcp = packet.getHeader(new Tcp());
ip.destination(dst.getAddress());
ip.source(src.getAddress());
ip.checksum(ip.calculateChecksum());
tcp.checksum(tcp.calculateChecksum());
packet.scan(Ethernet.ID);
System.out.println(packet);
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf
.toString());
return;
}
PcapIf device = alldevs.get(0); // We know we have atleast 1 device
/***************************************************************************
* Second we open a network interface
**************************************************************************/
int snaplen = 64 * 1024; // Capture all packets, no trucation
int flags = Pcap.MODE_NON_PROMISCUOUS; // capture all packets
int timeout = 10 * 1000; // 10 seconds in millis
Pcap pcap =
Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
System.out.println("Device ->" + device.getName());
try {
if (pcap.sendPacket(packet) != Pcap.OK) {
System.err.println(pcap.getErr());
}
} finally {
/*************************************************************************
* Lastly we close
************************************************************************/
pcap.close();
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:64,代码来源:TestTransmitter.java
注:本文中的org.jnetpcap.protocol.lan.Ethernet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论