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


Java EthernetPacket.newPacket方法代码示例

本文整理汇总了Java中org.pcap4j.packet.EthernetPacket.newPacket方法的典型用法代码示例。如果您正苦于以下问题:Java EthernetPacket.newPacket方法的具体用法?Java EthernetPacket.newPacket怎么用?Java EthernetPacket.newPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.pcap4j.packet.EthernetPacket的用法示例。


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

示例1: handleExportPcapFile

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
/**
 * Export stream to pcap file
 */
public void handleExportPcapFile() {
    try {
        Profile p = tabledata.getProfiles().get(streamPacketTableView.getSelectionModel().getSelectedIndex());
        String packetBinary = p.getStream().getPacket().getBinary();

        byte[] pkt = Base64.decodeBase64(packetBinary);
        Packet packet = EthernetPacket.newPacket(pkt, 0, pkt.length);
        File pcapFile = File.createTempFile("temp-file-name", ".pcap");
        PcapHandle handle = Pcaps.openDead(DataLinkType.EN10MB, 65536);
        PcapDumper dumper = handle.dumpOpen(pcapFile.getAbsolutePath());
        Timestamp ts = new Timestamp(0);
        dumper.dump(packet, ts);
        dumper.close();
        handle.close();

        String fileName = p.getName() + ".pcap";
        Window owner = streamPacketTableView.getScene().getWindow();
        FileManager.exportFile("Save Pcap File", fileName, pcapFile, owner, FileType.PCAP);
    } catch (IllegalRawDataException | IOException | PcapNativeException | NotOpenException ex) {
        LOG.error("Error during generate JSON file", ex);
    }
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:26,代码来源:PacketTableView.java

示例2: getPacketInfo

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
/**
 *
 * @param packetBinary
 * @return
 */
public PacketInfo getPacketInfo(String packetBinary) {

    PacketInfo packetInfo = null;

    try {
        byte[] pkt = Base64.decodeBase64(packetBinary);
        Packet packet = EthernetPacket.newPacket(pkt, 0, pkt.length);
        packetInfo = getPacketTypeText(packet);
    } catch (IllegalRawDataException ex) {
        LOG.error("Error reading packet info", ex);
    }

    return packetInfo;

}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:21,代码来源:TrafficProfile.java

示例3: buildIdealPkt

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
private static EthernetPacket buildIdealPkt(String pkt) {
    byte[] pktBin = Base64.getDecoder().decode(pkt);
    try {
        return EthernetPacket.newPacket(pktBin, 0, pktBin.length);
    } catch (IllegalRawDataException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:cisco-system-traffic-generator,项目名称:trex-java-sdk,代码行数:10,代码来源:TRexClientTest.java

示例4: processEthernetPacket

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
public static void processEthernetPacket(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
    if (packet == null) {
        return; // skip empty packets
    }
    try {
        log.trace("Converting to ethernet packet");
        EthernetPacket ethernetPacket = EthernetPacket.newPacket(packet.getRawData(), 0, packet.length());
        EthernetPacket.EthernetHeader ethernetHeader = ethernetPacket.getHeader();
        MacAddress sourceMac = ethernetHeader.getSrcAddr();
        log.trace("Source MAC: " + sourceMac);
        packetInfo.put(PacketInfo.SOURCE_MAC, sourceMac.toString());
        MacAddress destMac = ethernetHeader.getDstAddr();
        log.trace("Destination MAC: " + destMac);
        packetInfo.put(PacketInfo.DESTINATION_MAC, destMac.toString());
        EtherType etherType = ethernetHeader.getType();
        log.trace("EtherType: " + etherType.toString());
        packetInfo.put(PacketInfo.ETHERTYPE, etherType.toString());
        Packet payload = ethernetPacket.getPayload();
        if (etherType == EtherType.IPV4) {
            IpPacketProcessor.processIpv4Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if (etherType == EtherType.IPV6) {
            IpPacketProcessor.processIpv6Packet(payload, pcapFileSummary, packetInfo, mode);
        } else if ((mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) && (etherType == EtherType.ARP)) {
            pcapFileSummary.nonIpPacketCount++;
            ArpPacketProcessor.processArpPacket(payload, pcapFileSummary);
        } else {
            pcapFileSummary.nonIpPacketCount++;
            log.trace("Skipping packet with EtherType: " + etherType);
        }
    } catch (IllegalRawDataException e) {
        log.error("Exception occurred while processing a packet. Exception was: " + e);
    }
}
 
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:34,代码来源:PcapFileProcessor.java

示例5: fixPacketLength

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
private void fixPacketLength() {
    try {
        EthernetPacket newPacket = packet;
        if (packet.getRawData().length < getLength()) {
            byte[] pad = new byte[getLength() - packet.getRawData().length];
            newPacket = EthernetPacket.newPacket(ArrayUtils.addAll(packet.getRawData(), pad), 0, getLength());
        } else {
            newPacket = EthernetPacket.newPacket(packet.getRawData(), 0, getLength());
        }

        setPacket((EthernetPacket) newPacket);
    } catch (IllegalRawDataException ex) {
        Logger.getLogger(TrexEthernetPacket.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:16,代码来源:TrexEthernetPacket.java

示例6: handleMouseClickedEvent

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
/**
 * Handle mouse clicked event
 */
private void handleMouseClickedEvent() {
    TreeTableRow<HexData> selectedRow = (TreeTableRow<HexData>) textField.getParent().getParent();
    if (!selectedRow.getTreeItem().getValue().getOffset().contains("-")) {
        String originalLine = textField.getText();
        String selectedHex = textField.getSelectedText().trim();
        String replacedHex = showDialog(selectedHex);
        if (replacedHex != null) {
            try {
                textField.replaceSelection(replacedHex.toUpperCase());
                String payLoad = hexToASCII(textField.getText());
                TreeTableRow<HexData> hexTable = (TreeTableRow<HexData>) textField.getParent().getParent();
                TreeItem<HexData> selectedItem = hexTable.getTreeItem();
                selectedItem.setValue(new HexData(selectedItem.getValue().getOffset(), textField.getText(), packetParser.formatPayLoad(payLoad)));
                String originalHex = getPacketHexFromList();
                if (selectedItem.getValue().getOffset().contains("-")) {
                    originalHex = originalHex.replaceAll(originalLine.replaceAll(" ", "").replaceAll("\n", ""), textField.getText().replaceAll(" ", "").replaceAll("\n", ""));
                }
                byte[] rawdata = DatatypeConverter.parseHexBinary(originalHex);
                EthernetPacket p = EthernetPacket.newPacket(rawdata, 0, rawdata.length);
                packetParser.parsePacket(p, packetInfo);
                treeRoot.getChildren().clear();
                setData(packetInfo);
            } catch (IllegalRawDataException ex) {
                java.util.logging.Logger.getLogger(PacketHex.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:32,代码来源:PacketHex.java

示例7: getPacketFromEncodedString

import org.pcap4j.packet.EthernetPacket; //导入方法依赖的package包/类
/**
 * Get packet from encoded string
 *
 * @param encodedBinaryPacket
 * @return packet
 * @throws IllegalRawDataException
 */
public Packet getPacketFromEncodedString(String encodedBinaryPacket) throws IllegalRawDataException {
    byte[] pkt = Base64.decodeBase64(encodedBinaryPacket);
    return EthernetPacket.newPacket(pkt, 0, pkt.length);
}
 
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:12,代码来源:PacketUtil.java


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