本文整理汇总了Java中org.pcap4j.util.MacAddress类的典型用法代码示例。如果您正苦于以下问题:Java MacAddress类的具体用法?Java MacAddress怎么用?Java MacAddress使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MacAddress类属于org.pcap4j.util包,在下文中一共展示了MacAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: TCPTun
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
TCPTun(CapEnv capEnv,
Inet4Address serverAddress, short serverPort,
MacAddress srcAddress_mac, MacAddress dstAddrress_mac){
this.capEnv=capEnv;
sendHandle=capEnv.sendHandle;
this.remoteAddress=serverAddress;
this.remotePort=serverPort;
localAddress=capEnv.local_ipv4;
localPort=(short)(random.nextInt(64*1024-1-10000)+10000);
Packet syncPacket=null;
try {
syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,serverAddress, serverPort, localStartSequence,getIdent());
try {
sendHandle.sendPacket(syncPacket);
localSequence=localStartSequence+1;
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
MLog.println("发送第一次握手 "+" ident "+localIdent);
MLog.println(""+syncPacket);
}
示例2: getMacAddress
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
public MacAddress getMacAddress(InetAddress address) {
if (address == null) {
throw new IllegalArgumentException("Address is null");
}
if (!_initted) {
throw new IllegalStateException("Fail to init component", _initError);
}
if (_localAddresse2MacAddress.containsKey(address)) {
return _localAddresse2MacAddress.get(address);
}
try {
return _getMacAddress(address);
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例3: _getPacketBuilder4IPv4
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private EthernetPacket.Builder _getPacketBuilder4IPv4(InetAddress remoteAddress, MacAddress localMacAddress, InetAddress
localIpAdress) {
ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
arpBuilder
.hardwareType(ArpHardwareType.ETHERNET)
.protocolType(EtherType.IPV4)
.hardwareAddrLength((byte) MacAddress.SIZE_IN_BYTES)
.protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
.srcHardwareAddr(localMacAddress)
.srcProtocolAddr(localIpAdress)
.dstHardwareAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
.operation(ArpOperation.REQUEST)
.dstProtocolAddr(remoteAddress);
EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
etherBuilder.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
.srcAddr(localMacAddress)
.type(EtherType.ARP)
.payloadBuilder(arpBuilder)
.paddingAtBuild(true);
return etherBuilder;
}
示例4: TCPTun
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
TCPTun(CapEnv capEnv,
Inet4Address serverAddress,short serverPort,
MacAddress srcAddress_mac,MacAddress dstAddrress_mac){
this.capEnv=capEnv;
sendHandle=capEnv.sendHandle;
this.remoteAddress=serverAddress;
this.remotePort=serverPort;
localAddress=capEnv.local_ipv4;
localPort=(short)(random.nextInt(64*1024-1-10000)+10000);
Packet syncPacket=null;
try {
syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,serverAddress, serverPort, localStartSequence,getIdent());
try {
sendHandle.sendPacket(syncPacket);
localSequence=localStartSequence+1;
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
MLog.println("发送第一次握手 "+" ident "+localIdent);
MLog.println(""+syncPacket);
}
示例5: processArpPacket
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
public static void processArpPacket(Packet packet, PcapFileSummary pcapFileSummary) {
if (packet == null) {
return; // skip empty packets
}
log.trace("Converting to ARP packet");
try {
ArpPacket arpPacket = ArpPacket.newPacket(packet.getRawData(), 0, packet.length());
ArpPacket.ArpHeader arpHeader = arpPacket.getHeader();
ArpOperation arpOperation = arpHeader.getOperation();
InetAddress sourceIp = arpHeader.getSrcProtocolAddr();
MacAddress sourceMac = arpHeader.getSrcHardwareAddr();
if (arpOperation == ArpOperation.REQUEST) {
// only add / check the source addresses for an ARP request
//IpMacTrackerResult result = pcapFileSummary.ipMacTracker.query(sourceIp.getHostAddress(), sourceMac.toString());
}
} catch (IllegalRawDataException e) {
log.error("Exception occurred while processing a packet. Exception was: " + e);
}
}
示例6: TCPTun
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
TCPTun(CapEnv capEnv,
Inet4Address serverAddress,short serverPort,
MacAddress srcAddress_mac,MacAddress dstAddrress_mac){
this.capEnv=capEnv;
sendHandle=capEnv.sendHandle;
this.remoteAddress=serverAddress;
this.remotePort=serverPort;
localAddress=capEnv.local_ipv4;
localPort=(short)(random.nextInt(64*1024-1-10000)+10000);
Packet syncPacket=null;
try {
syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,serverAddress, serverPort, localStartSequence,getIdent());
try {
sendHandle.sendPacket(syncPacket);
localSequence=localStartSequence+1;
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
MLog.println("Sending first handshake ident "+localIdent);
MLog.println(""+syncPacket);
}
示例7: TCPTun
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
TCPTun(CapEnv capEnv,
Inet4Address serverAddress, short serverPort,
MacAddress srcAddress_mac, MacAddress dstAddrress_mac) {
this.capEnv = capEnv;
sendHandle = capEnv.sendHandle;
this.remoteAddress = serverAddress;
this.remotePort = serverPort;
localAddress = capEnv.local_ipv4;
localPort = (short) (random.nextInt(64 * 1024 - 1 - 10000) + 10000);
Packet syncPacket = null;
try {
syncPacket = PacketUtils.createSync(srcAddress_mac, dstAddrress_mac, localAddress, localPort,
serverAddress, serverPort, localStartSequence, getIdent());
try {
sendHandle.sendPacket(syncPacket);
localSequence = localStartSequence + 1;
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e1) {
e1.printStackTrace();
}
MLog.println("发送第一次握手 " + " ident " + localIdent);
MLog.println("" + syncPacket);
}
示例8: generateVirtualMacAddress
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
public MacAddress generateVirtualMacAddress() {
int serialNumber;
synchronized (counterLock) {
if (counter > MAX_SERIAL_NUMBER) {
throw new AssertionError("too many MAC addresses.");
}
serialNumber = counter;
counter++;
}
// TODO IPv6
byte[] rawAddr = new byte[6];
System.arraycopy(
VIRTUAL_MACADDRESS_OUI.valueAsByteArray(), 0, rawAddr, 0, 3
);
System.arraycopy(
ByteArrays.toByteArray(serialNumber), 1, rawAddr, 3, 3
);
MacAddress macAddr = MacAddress.getByAddress(rawAddr);
return macAddr;
}
示例9: cache
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private void cache(InetAddress ipAddr, MacAddress macAddr) {
synchronized (table) {
if (invalidateNeighborCacheFutures.containsKey(ipAddr)) {
invalidateNeighborCacheFutures.get(ipAddr).cancel(true);
}
if (table.containsKey(ipAddr)) {
FutureData<MacAddress> f = table.get(ipAddr);
f.set(macAddr);
}
else {
table.put(ipAddr, new FutureData<MacAddress>(macAddr));
}
invalidateNeighborCacheFutures.put(
ipAddr,
scheduler.schedule(
new NeighborCacheInvalidater(ipAddr), cacheLife, TimeUnit.MILLISECONDS
)
);
}
}
示例10: resolveRealAddress
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
public static MacAddress resolveRealAddress(
InetAddress targetIpAddr,
Node node,
NetworkInterface nif,
NdpCache ndpCache,
long resolveTimeout,
TimeUnit unit
) {
return resolveRealAddress(
ndpReqSender,
targetIpAddr,
node,
nif,
ndpCache,
resolveTimeout,
unit
);
}
示例11: cacheByNa
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private static void cacheByNa(Packet packet, NdpCache ndpCache) {
IcmpV6NeighborAdvertisementPacket naPacket
= packet.get(IcmpV6NeighborAdvertisementPacket.class);
InetAddress ipAddr = naPacket.getHeader().getTargetAddress();
MacAddress macAddr = null;
for (IpV6NeighborDiscoveryOption opt: naPacket.getHeader().getOptions()) {
if (opt.getType().equals(IpV6NeighborDiscoveryOptionType.TARGET_LINK_LAYER_ADDRESS)) {
macAddr
= ((IpV6NeighborDiscoveryTargetLinkLayerAddressOption)opt).getLinkLayerAddressAsMacAddress();
}
}
if (macAddr == null) {
return;
}
// According to RFC 2461, If no entry exists, the advertisement SHOULD be silently discarded.
// But cache it here with no check for entry existance.
NeighborDiscoveryHelper.cache(ndpCache, ipAddr, macAddr);
}
示例12: resolveRealAddress
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
public static MacAddress resolveRealAddress(
InetAddress targetIpAddr,
Node node,
NetworkInterface nif,
ArpCache arpCache,
long resolveTimeout,
TimeUnit unit
) {
return resolveRealAddress(
reqSender,
targetIpAddr,
node,
nif,
arpCache,
resolveTimeout,
unit
);
}
示例13: multicastMacFromIPv6
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private static MacAddress multicastMacFromIPv6(String ipV6) {
String expandedIPv6 = expandIPv6Address(ipV6);
List<Long> ipv6Octets = Arrays.stream(expandedIPv6.split(":"))
.map(octet -> Long.parseLong(octet, 16))
.collect(Collectors.toList());
int lastIdx = ipv6Octets.size() - 1;
int preLastIdx = ipv6Octets.size() - 2;
String macAddressStr = String.format("33:33:%02x:%02x:%02x:%02x", divMod(ipv6Octets.get(preLastIdx), 256)[0],
divMod(ipv6Octets.get(preLastIdx), 256)[1],
divMod(ipv6Octets.get(lastIdx), 256)[0],
divMod(ipv6Octets.get(lastIdx), 256)[1]);
return MacAddress.getByName(macAddressStr);
}
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:15,代码来源:IPv6NeighborDiscoveryService.java
示例14: buildArpPkt
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private static EthernetPacket buildArpPkt(String srcMac, String srcIp, String dstIp) {
ArpPacket.Builder arpBuilder = new ArpPacket.Builder();
MacAddress srcMacAddress = MacAddress.getByName(srcMac);
try {
arpBuilder
.hardwareType(ArpHardwareType.ETHERNET)
.protocolType(EtherType.IPV4)
.hardwareAddrLength((byte) MacAddress.SIZE_IN_BYTES)
.protocolAddrLength((byte) ByteArrays.INET4_ADDRESS_SIZE_IN_BYTES)
.operation(ArpOperation.REQUEST)
.srcHardwareAddr(srcMacAddress)
.srcProtocolAddr(InetAddress.getByName(srcIp))
.dstHardwareAddr(MacAddress.getByName("00:00:00:00:00:00"))
.dstProtocolAddr(InetAddress.getByName(dstIp));
} catch (UnknownHostException e) {
throw new IllegalArgumentException(e);
}
EthernetPacket.Builder etherBuilder = new EthernetPacket.Builder();
etherBuilder.dstAddr(MacAddress.ETHER_BROADCAST_ADDRESS)
.srcAddr(srcMacAddress)
.type(EtherType.ARP)
.payloadBuilder(arpBuilder)
.paddingAtBuild(true);
return etherBuilder.build();
}
示例15: buildIcmpV4Request
import org.pcap4j.util.MacAddress; //导入依赖的package包/类
private EthernetPacket buildIcmpV4Request(String srcMac, String dstMac, String srcIp, String dstIp, int reqId, int seqNumber) throws UnknownHostException {
IcmpV4EchoPacket.Builder icmpReqBuilder = new IcmpV4EchoPacket.Builder();
icmpReqBuilder.identifier((short) reqId);
icmpReqBuilder.sequenceNumber((short) seqNumber);
IcmpV4CommonPacket.Builder icmpv4CommonPacketBuilder = new IcmpV4CommonPacket.Builder();
icmpv4CommonPacketBuilder.type(IcmpV4Type.ECHO)
.code(IcmpV4Code.NO_CODE)
.correctChecksumAtBuild(true)
.payloadBuilder(icmpReqBuilder);
IpV4Packet.Builder ipv4Builder = new IpV4Packet.Builder();
ipv4Builder.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.ttl((byte) 64)
.protocol(IpNumber.ICMPV4)
.srcAddr((Inet4Address) Inet4Address.getByName(srcIp))
.dstAddr((Inet4Address) Inet4Address.getByName(dstIp))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(icmpv4CommonPacketBuilder);
EthernetPacket.Builder eb = new EthernetPacket.Builder();
eb.srcAddr(MacAddress.getByName(srcMac))
.dstAddr(MacAddress.getByName(dstMac))
.type(EtherType.IPV4)
.paddingAtBuild(true)
.payloadBuilder(ipv4Builder);
return eb.build();
}