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


Java PacketListener类代码示例

本文整理汇总了Java中org.pcap4j.core.PacketListener的典型用法代码示例。如果您正苦于以下问题:Java PacketListener类的具体用法?Java PacketListener怎么用?Java PacketListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PacketListener类属于org.pcap4j.core包,在下文中一共展示了PacketListener类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gotPacket

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public void gotPacket(Packet packet) {
  for (PacketListener user: users) {
    user.gotPacket(packet);
  }

  if (EthernetHelper.matchesDestination(packet, macAddress)) {
    host.gotPacket(packet);
  }
  else {
    if (logger.isDebugEnabled()) {
      StringBuilder sb = new StringBuilder();
      sb.append("Dropped a packet not to me(")
        .append(macAddress)
        .append("): ")
        .append(packet);
      logger.debug(sb.toString());
    }
  }
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:20,代码来源:LagInterface.java

示例2: readTOPSsample

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
private void readTOPSsample() throws PcapNativeException, InterruptedException, NotOpenException {
    final PcapHandle handle = Pcaps.openOffline("C:\\Users\\wojci\\Desktop\\IEX\\20171104_IEXTP1_TOPS1.6.pcap", PcapHandle.TimestampPrecision.NANO);

    handle.loop(-1, new PacketListener() {
        @Override
        public void gotPacket(final Packet packet) {
            final byte[] data = packet.getPayload().getPayload().getPayload().getRawData();
            final IEXSegment block = IEXTOPSMessageBlock.createIEXSegment(data);
            System.out.println(block);
        }
    });

    handle.close();
}
 
开发者ID:WojciechZankowski,项目名称:iextrading4j-hist,代码行数:15,代码来源:TOPSSample.java

示例3: readDEEPsample

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
private void readDEEPsample() throws PcapNativeException, InterruptedException, NotOpenException {
    final PcapHandle handle = Pcaps.openOffline("path_to_pcap", PcapHandle.TimestampPrecision.MICRO);

    handle.loop(-1, new PacketListener() {
        @Override
        public void gotPacket(final Packet packet) {
            final byte[] data = packet.getPayload().getPayload().getPayload().getRawData();
            final IEXSegment block = IEXDEEPMessageBlock.createIEXSegment(data);
            System.out.println(block);
        }
    });

    handle.close();
}
 
开发者ID:WojciechZankowski,项目名称:iextrading4j-hist,代码行数:15,代码来源:DEEPSample.java

示例4: readDEEPSample

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
private void readDEEPSample() throws PcapNativeException, NotOpenException, InterruptedException {
    final PcapHandle handle = Pcaps.openOffline("path_to_pcap", PcapHandle.TimestampPrecision.NANO);

    handle.loop(-1, new PacketListener() {
        @Override
        public void gotPacket(Packet packet) {
            final byte[] data = packet.getPayload().getPayload().getPayload().getRawData();
            final IEXSegment block = IEXDEEPMessageBlock.createIEXSegment(data);

            for (final IEXMessage iexMessage : block.getMessages()) {
                if (iexMessage instanceof IEXPriceLevelUpdateMessage) {
                    final IEXPriceLevelUpdateMessage iexPriceLevelUpdateMessage = (IEXPriceLevelUpdateMessage) iexMessage;
                    final IEXOrderBook iexOrderBook = orderBookStore.getOrderBook(iexPriceLevelUpdateMessage.getSymbol())
                            .orElseGet(() -> new IEXOrderBook(iexPriceLevelUpdateMessage.getSymbol()));
                    iexOrderBook.priceLevelUpdate(iexPriceLevelUpdateMessage);
                    orderBookStore.updateOrderBook(iexOrderBook);

                    if (iexOrderBook.getSymbol().equals("AAPL")) {
                        System.out.println(iexOrderBook);
                    }
                }
            }
        }
    });


    handle.close();
}
 
开发者ID:WojciechZankowski,项目名称:iextrading4j-book,代码行数:29,代码来源:OrderBookSample.java

示例5: VlanInterface

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public VlanInterface(
  String name,
  MacAddress macAddress,
  int vid,
  PacketListener host
) {
  this.name = name;
  this.macAddress = macAddress;
  this.vid = vid;
  this.host = host;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:12,代码来源:VlanInterface.java

示例6: PhysicalNetworkInterface

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public PhysicalNetworkInterface(
  String name,
  MacAddress macAddress,
  boolean trunk,
  PacketListener host
) {
  super(name);
  this.macAddress = macAddress;
  this.trunk = trunk;
  this.host = host;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:12,代码来源:PhysicalNetworkInterface.java

示例7: LagInterface

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public LagInterface(
  String name,
  MacAddress macAddress,
  int channelGroupNumber,
  PacketListener host
) {
  this.name = name;
  this.macAddress = macAddress;
  this.channelGroupNumber = channelGroupNumber;
  this.host = host;
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:12,代码来源:LagInterface.java

示例8: ReceiveTask

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public ReceiveTask(PcapHandle receiveHandle, PacketListener listener, CyclicBarrier cyclicBarrier) {
    this.receiveHandle = receiveHandle;
    this.listener = listener;
    this.cyclicBarrier = cyclicBarrier;
}
 
开发者ID:gaoxingliang,项目名称:mac-address-detector-java,代码行数:6,代码来源:MacAddressHelper.java

示例9: startCapturing

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
/**
 * Starts the capturing in a dedicated thread, so this method returns immediately. Every time a packet is captured,
 * the {@link PacketCapturingHandler#packetCaptured(MacAddress)} of the given
 * {@link PacketCapturingHandler} is called.
 *
 * It's possible to capture packets sent by a specific MAC address by providing the given parameter. If the
 * macAddress is null, all MAC addresses are considered.
 *
 * @param packetCapturingHandler The handler to be called every time a packet is captured
 * @param macAddress The source MAC address of the captured packet, might be null in order to deactivate this filter
 *            criteria
 * @return Returns true, if the capturing has been started successfully, otherwise returns false
 * @throws IllegalStateException Thrown if {@link PcapHandle#isOpen()} of {@link #pcapHandle} returns true
 */

public boolean startCapturing(final PacketCapturingHandler packetCapturingHandler, final String macAddress) {
    if (pcapHandle != null) {
        if (pcapHandle.isOpen()) {
            throw new IllegalStateException("There is an open pcap handle.");
        } else {
            pcapHandle.close();
        }
    }
    try {
        pcapHandle = pcapNetworkInterface.openLive(SNAPLEN, PromiscuousMode.PROMISCUOUS, READ_TIMEOUT);
        StringBuilder filterBuilder = new StringBuilder("(arp or port bootps)");
        if (macAddress != null) {
            filterBuilder.append(" and ether src " + macAddress);
        }
        pcapHandle.setFilter(filterBuilder.toString(), BpfCompileMode.OPTIMIZE);
    } catch (Exception e) {
        logger.error("Capturing packets on device {} failed.", pcapNetworkInterface.getName(), e);
        return false;
    }
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.submit(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            try {
                pcapHandle.loop(-1, new PacketListener() {

                    @Override
                    public void gotPacket(Packet packet) {
                        if (!packet.contains(EthernetPacket.class)) {
                            return;
                        }
                        final EthernetPacket ethernetPacket = packet.get(EthernetPacket.class);
                        final MacAddress sourceMacAddress = ethernetPacket.getHeader().getSrcAddr();
                        if (shouldCapture(packet)) {
                            packetCapturingHandler.packetCaptured(sourceMacAddress);
                        }
                    }
                });
            } finally {
                if (pcapHandle != null && pcapHandle.isOpen()) {
                    pcapHandle.close();
                    pcapHandle = null;
                }
            }
            return null;
        }
    });
    if (macAddress == null) {
        logger.debug("Started capturing ARP and BOOTP requests for network device {}.",
                pcapNetworkInterface.getName());
    } else {
        logger.debug("Started capturing ARP  and BOOTP requests for network device {} and MAC address {}.",
                pcapNetworkInterface.getName(), macAddress);
    }
    return true;
}
 
开发者ID:openhab,项目名称:openhab2-addons,代码行数:73,代码来源:PacketCapturingService.java

示例10: addUser

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public void addUser(PacketListener user) {
  users.add(user);
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:4,代码来源:VlanInterface.java

示例11: addUser

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
@Deprecated
public void addUser(PacketListener user) {
  throw new UnsupportedOperationException();
}
 
开发者ID:kaitoy,项目名称:sneo,代码行数:5,代码来源:RealNetworkInterface.java

示例12: addUser

import org.pcap4j.core.PacketListener; //导入依赖的package包/类
public void addUser(PacketListener user); 
开发者ID:kaitoy,项目名称:sneo,代码行数:2,代码来源:NetworkInterface.java


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