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


Java PcapPacket类代码示例

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


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

示例1: getByteLimitedHandler

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Creation of a pseudopackethandler packet handler type which breaks the loop after.
 *
 * @return returns a packethandler which handles' the packets and stops if the max_bytes amount is handled.
 */
private static PcapPacketHandler<PseudoPacketHandler> getByteLimitedHandler(final Pcap pcap, final long MAX_BYTES) {
    // Packet handler. Generic callback function for PseudoPacketHandler.
    return new PcapPacketHandler<PseudoPacketHandler>() {
        long packetBytes = 0;

        // Handle nextPacket callback.
        public void nextPacket(PcapPacket packet, PseudoPacketHandler handler) {
            handler.handle(packet);
            packetBytes+= packet.size();
            if (packetBytes >= MAX_BYTES) {
                pcap.breakloop();
            }
        }
    };
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:21,代码来源:PcapSniffer.java

示例2: getPacketList

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Gets the packet list.
 * 
 * @param file
 *            the file
 * @return the packet list
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private List<PcapPacket> getPacketList(String file) throws IOException {
	StringBuilder errbuf = new StringBuilder();
	Pcap pcap = Pcap.openOffline(file, errbuf);
	if (pcap == null) {
		throw new IOException(errbuf.toString());
	}

	final PcapPacketArrayList list = new PcapPacketArrayList(
			(int) new File(file).length() / 100);

	pcap.loop(Pcap.LOOP_INFINATE, list, null);

	pcap.close();

	return list;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:26,代码来源:TestTcpIp.java

示例3: testScanIpv6File

import org.jnetpcap.packet.PcapPacket; //导入依赖的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

示例4: handle

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * pseudonymize the packet as configured.
 *
 * @param packet the captured PcapPacket
 */
@Override
public void handle(PcapPacket packet) {
    //Copy the data.
    byte[] packetData = packet.getByteArray(0, packet.size());
    try {
        // If parsing fails the packet is not pseudonymized. This should logged at a lower level TODO PEF-77.
        // Packet should be discarded because pseudonymization is not guaranteed otherwise.
        final byte[] pseudopacketData  = _pseudonymizer.pseudonymize(packetData);
        PcapPacket copyPacket = new PcapPacket(packet.getCaptureHeader(), ByteBuffer.wrap(pseudopacketData));
        _pseudoDumper.dump(copyPacket);
    }
    catch (final IOException e) {
        logger.severe(e.getMessage());
    }
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:21,代码来源:PEFPseudonymizeDumper.java

示例5: handle

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Handles the packets and writes the packet after modification with the metal library,
 * JNetPcap library and stores a reference file.
 *
 * @param packet the captured PcapPacket
 */
@Override
public void handle(PcapPacket packet) {
    _referenceDumper.dump(packet);

    byte[] packetData = packet.getByteArray(0, packet.size());
    try {
        final byte[] pseudopacketData  = _pseudonymizer.pseudonymize(packetData);
        PcapPacket copyPacket = new PcapPacket(packet.getCaptureHeader(), ByteBuffer.wrap(pseudopacketData));
        _metalDumper.dump(copyPacket);
    } catch (final IOException ioexc) {
        logger.severe("problem when pseudonymizing packets with the metal library");
    }
    _packetModifier.modifyPacket(packet);
    _jnetpcapDumper.dump(packet);
}
 
开发者ID:NCSC-NL,项目名称:PEF,代码行数:22,代码来源:TestPseudonymizerLibs.java

示例6: setPacket

import org.jnetpcap.packet.PcapPacket; //导入依赖的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

示例7: startCapture

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@FXML
protected void startCapture(ActionEvent event) {
    MenuItem source = (MenuItem) event.getSource();
    NetworkAdapter networkAdapter = PcapManager.getInstance().getNetworkAdapter();
    if (networkAdapter == null) {
        showCaptureOptions(null);
        return;
    }

    setStatusInfo(Config.getString("label_start_capture"));
    source.setDisable(true);
    menuItemStop.setDisable(false);

    PcapManager.getInstance().captureLive(packet -> {
        // 将第一个数据包的时间戳设置为起始时间
        if (Config.getTimestamp() <= Config.DEFAULT_TIMESTAMP) {
            Config.setTimestamp(packet.getCaptureHeader().timestampInMicros());
        }

        PcapPacket packetCopy = new PcapPacket(packet); // 获取副本
        ObservableList items = tableView.getItems();
        items.add(new PacketInfo(packetCopy));
    });
}
 
开发者ID:whinc,项目名称:PcapAnalyzer,代码行数:25,代码来源:MainFormController.java

示例8: meetCriteria

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
	if (!itemToCheck.hasHeader(Ip4.ID))
		return false;
	
	Ip4 ipHeader = new Ip4();
	ipHeader = itemToCheck.getHeader(ipHeader);
	
	if (direction == null) //direction wasn't set, so any direction
		return subnetInfo.isInRange(ipHeader.sourceToInt()) || subnetInfo.isInRange(ipHeader.destinationToInt());
	
	switch(direction)
	{
		case Incoming:	return subnetInfo.isInRange(ipHeader.sourceToInt());
		case Outgoing:	return subnetInfo.isInRange(ipHeader.destinationToInt());
		default:		return null; //doesn't get here
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:20,代码来源:CriteriaIP.java

示例9: meetCriteria

import org.jnetpcap.packet.PcapPacket; //导入依赖的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

示例10: nextPacket

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
@Override
public void nextPacket(PcapPacket packet, Void nothing)
{
	if (!isCooldownPeriod)
	{
		for (Criteria<PcapPacket, Boolean> criteria : criteriaList)
		{
			if (criteria.meetCriteria(packet))
			{
				if (isRepeated)
				{
					isCooldownPeriod = true;

					timer.schedule(() -> isCooldownPeriod = false, cooldownInSecs, TimeUnit.SECONDS);
				}
				else
					sniffer.stopCapture();

				listener.watchdogFoundMatchingPacket(packet, criteriaToMsgMap.get(criteria));
			}
		}
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:24,代码来源:WatchdogPacketHandler.java

示例11: convertPacketTypeToMatchListToCriteria

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
private List<Criteria<PcapPacket, Boolean>> convertPacketTypeToMatchListToCriteria(List<PacketTypeToMatch> packetTypeList)
{
	List<Criteria<PcapPacket, Boolean>> criterias = new ArrayList<>();

	for (PacketTypeToMatch item : packetTypeList)
	{
		Criteria<PcapPacket, Boolean> andCriteria = null;
		List<Criteria<PcapPacket, Boolean>> criteriasToAND = generateCriteriasToAND(item);

		if (criteriasToAND.size() > 0)
			andCriteria = criteriasToAND.get(0);

		for (int i = 1; i < criteriasToAND.size(); i++)
			andCriteria = new AndCriteria<PcapPacket>(andCriteria, criteriasToAND.get(i));

		if (criteriasToAND.size() > 0)
		{
			criterias.add(andCriteria);
			criteriaToMsgMap.put(andCriteria, new WatchdogMessage(item.getMessageTextValue(), item.getMessageOutputMethodValue()));
		}
	}

	return criterias;
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:25,代码来源:WatchdogPacketHandler.java

示例12: testSip

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Test sip.
 */
public void testSip() {
	Sip sip = new Sip();
	Sdp sdp = new Sdp();
	PcapPacket packet = super.getPcapPacket(SIP, 223 - 1);
	if (packet.hasHeader(sip)) {
		System.out.printf("%s", sip);

		if (packet.hasHeader(sdp)) {
			System.out.printf("%s", sdp);

		}
	} else {
		System.out.printf(packet.toString());
	}
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:19,代码来源:TestVoip.java

示例13: testCompare2SetsOfPackets

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Test compare2 sets of packets.
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void testCompare2SetsOfPackets() throws IOException {
	List<PcapPacket> l1 = getPacketList(L2TP);
	List<PcapPacket> l2 = getPacketList(L2TP);

	assertEquals(l1.size(), l2.size());

	for (int i = 0; i < l1.size(); i++) {
		PcapPacket p1 = l1.get(i);
		PcapPacket p2 = l2.get(i);

		if (p1.size() != p2.size()) {
			System.out.printf("#%d p1=%d p2=%d\n%s\n%s\n", i, l1.size(),
					l2.size(), p1.toHexdump(), p2.toHexdump());

			System.out.println(p1.toString());
			System.out.println(p2.toString());
		}

		assertEquals(p1.size(), p2.size());
		assertTrue(compareJBuffer(p1, p2));

	}

}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:31,代码来源:TestTcpIp.java

示例14: testCompare2SetsOfPackets2

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
/**
 * Test compare2 sets of packets2.
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
public void testCompare2SetsOfPackets2() throws IOException {
	List<PcapPacket> l1 = getPacketList(L2TP);
	List<PcapPacket> l2 = getPacketList(L2TP);
	Ip4 ip1 = new Ip4();
	Ip4 ip2 = new Ip4();

	assertEquals(l1.size(), l2.size());

	System.out.println("------------------------------\n");

	for (int i = 0; i < l1.size(); i++) {
		PcapPacket p1 = l1.get(i);
		PcapPacket p2 = l2.get(i);
		p1.getHeader(ip1);
		p2.getHeader(ip2);

		assertTrue("ip1.size() == p2.size()", p1.size() == p2.size());

		assertTrue(ip1.toString(), ip1.isChecksumValid());
		assertTrue(ip2.toString(), ip2.isChecksumValid());
		assertTrue(compareJBuffer(p1, p2));

	}

}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:32,代码来源:TestTcpIp.java

示例15: onPreExecute

import org.jnetpcap.packet.PcapPacket; //导入依赖的package包/类
protected void onPreExecute(){
	blockLength=PcapFileLoader.blockLength;
	pcapPackets=new PcapPacket[blockLength.value];
	PcapFileLoader.pcapPackets[block]=pcapPackets;
	lowerBound=new IntHolder(targetPacket);
	
	if (indeterminate[block] || targetPacket<= PcapFileLoader.range[block][1].value){
		if (!indeterminate[block]){
			PcapFileLoader.pcap[block].close();
		}
		JScanner.getThreadLocal().setFrameNumber(0);
		final StringBuilder errbuf=new StringBuilder();
		pcap =  Pcap.openOffline(filename, errbuf);
		currentPacket=new IntHolder(0);
		PcapFileLoader.pcap[block]=pcap;
		PcapFileLoader.range[block][1]=currentPacket;
	} else {
		pcap=PcapFileLoader.pcap[block];
		currentPacket=PcapFileLoader.range[block][1];
	}
	PcapFileLoader.range[block][0]=lowerBound;
	indeterminate[block]=true;
	Log.d("PcapBlockLoadTask", "loading block: "+Integer.toString(block)+"|"+Integer.toString(lowerBound.value));
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:25,代码来源:PcapFileLoader.java


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