当前位置: 首页>>代码示例>>Java>>正文


Java MacAddress类代码示例

本文整理汇总了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);
	
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:26,代码来源:TCPTun.java

示例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;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:19,代码来源:MacAddressHelper.java

示例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;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:25,代码来源:MacAddressHelper.java

示例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);
	
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:26,代码来源:TCPTun.java

示例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);
    }
}
 
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:22,代码来源:ArpPacketProcessor.java

示例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);
	
}
 
开发者ID:RCD-Y,项目名称:FinalSpeed-X,代码行数:26,代码来源:TCPTun.java

示例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);

}
 
开发者ID:Bpazy,项目名称:finalspeed,代码行数:27,代码来源:TCPTun.java

示例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;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:23,代码来源:MacAddressManager.java

示例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
      )
    );
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:23,代码来源:NeighborDiscoveryHelper.java

示例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
  );
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:19,代码来源:IcmpV6Helper.java

示例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);
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:21,代码来源:IcmpV6Helper.java

示例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
  );
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:19,代码来源:ArpHelper.java

示例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();
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:28,代码来源:TRexClient.java

示例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();
    }
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:33,代码来源:TRexClient.java


注:本文中的org.pcap4j.util.MacAddress类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。