本文整理汇总了Java中org.pcap4j.packet.IllegalRawDataException类的典型用法代码示例。如果您正苦于以下问题:Java IllegalRawDataException类的具体用法?Java IllegalRawDataException怎么用?Java IllegalRawDataException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IllegalRawDataException类属于org.pcap4j.packet包,在下文中一共展示了IllegalRawDataException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIpV4Packet_pppoe
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException{
IpV4Packet ipV4Packet=null;
byte[] pppData=packet_eth.getPayload().getRawData();
if(pppData.length>8&&pppData[8]==0x45){
byte[] b2=new byte[2];
System.arraycopy(pppData, 4, b2, 0, 2);
short len=(short) ByteShortConvert.toShort(b2, 0);
int ipLength=toUnsigned(len)-2;
byte[] ipData=new byte[ipLength];
//设置ppp参数
PacketUtils.pppHead_static[2]=pppData[2];
PacketUtils.pppHead_static[3]=pppData[3];
if(ipLength==(pppData.length-8)){
System.arraycopy(pppData, 8, ipData, 0, ipLength);
ipV4Packet=IpV4Packet.newPacket(ipData, 0, ipData.length);
}else {
MLog.println("长度不符!");
}
}
return ipV4Packet;
}
示例2: processUdpPacket
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
public static void processUdpPacket(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
if (packet == null) {
return; // skip empty packets
}
String sourceAddress = packetInfo.get(PacketInfo.SOURCE_ADDRESS);
String destinationAddress = packetInfo.get(PacketInfo.DESTINATION_ADDRESS);
try {
log.trace("Converting to UDP packet");
UdpPacket udpPacket = UdpPacket.newPacket(packet.getRawData(), 0, packet.length());
UdpPacket.UdpHeader udpHeader = udpPacket.getHeader();
UdpPort sourcePort = udpHeader.getSrcPort();
UdpPort destinationPort = udpHeader.getDstPort();
packetInfo.put(PacketInfo.SOURCE_PORT, sourcePort.valueAsString());
packetInfo.put(PacketInfo.DESTINATION_PORT, destinationPort.valueAsString());
if (mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) {
//pcapFileSummary.portScanDetector.add(packetInfo);
}
String udpSource = sourceAddress + ":" + sourcePort.toString();
String udpDestination = destinationAddress + ":" + destinationPort.toString();
log.trace("Adding UDP source to set: " + udpSource);
pcapFileSummary.udpSources.add(udpSource);
log.trace("UDP{ source: " + udpSource + ", destination: " + udpDestination + " }");
} catch (IllegalRawDataException e) {
log.error("Exception occurred while processing a packet. Exception was: " + e);
}
}
示例3: processArpPacket
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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);
}
}
示例4: getIpV4Packet_pppoe
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException{
IpV4Packet ipV4Packet=null;
byte[] pppData=packet_eth.getPayload().getRawData();
if(pppData.length>8&&pppData[8]==0x45){
byte[] b2=new byte[2];
System.arraycopy(pppData, 4, b2, 0, 2);
short len=(short) ByteShortConvert.toShort(b2, 0);
int ipLength=toUnsigned(len)-2;
byte[] ipData=new byte[ipLength];
//设置ppp参数
PacketUtils.pppHead_static[2]=pppData[2];
PacketUtils.pppHead_static[3]=pppData[3];
if(ipLength==(pppData.length-8)){
System.arraycopy(pppData, 8, ipData, 0, ipLength);
ipV4Packet=IpV4Packet.newPacket(ipData, 0, ipData.length);
}else {
MLog.println("Length don't match!");
}
}
return ipV4Packet;
}
示例5: handleExportPcapFile
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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);
}
}
示例6: getPacketInfo
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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;
}
示例7: buildIdealPkt
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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;
}
示例8: processEthernetPacket
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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);
}
}
示例9: processIpv6Packet
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
public static void processIpv6Packet(Packet packet, PcapFileSummary pcapFileSummary, PacketInfo packetInfo, Mode mode) {
if (packet == null) {
return; // skip empty packets
}
try {
log.trace("Converting to IPv6 packet");
IpV6Packet ipV6Packet = IpV6Packet.newPacket(packet.getRawData(), 0, packet.length());
IpV6Packet.IpV6Header ipV6Header = ipV6Packet.getHeader();
Inet6Address sourceAddress = ipV6Header.getSrcAddr();
Inet6Address destAddress = ipV6Header.getDstAddr();
if (mode == Mode.POSSIBLE_ATTACKS_ANALYSIS) {
//pcapFileSummary.ipMacTracker.query(sourceAddress.getHostAddress(), sourceMac.toString());
}
packetInfo.put(PacketInfo.SOURCE_ADDRESS, sourceAddress.getHostAddress());
packetInfo.put(PacketInfo.DESTINATION_ADDRESS, destAddress.getHostAddress());
log.trace("Adding IPv6 addresses to set: source: " + sourceAddress.getHostAddress() + ", dest: " + destAddress.getHostAddress());
pcapFileSummary.uniqueIpAddresses.add(sourceAddress.getHostAddress());
pcapFileSummary.uniqueIpAddresses.add(destAddress.getHostAddress());
IpNumber ipNumber = ipV6Header.getProtocol();
packetInfo.put(PacketInfo.IP_PROTOCOL, ipNumber.toString());
pcapFileSummary.ipProtocolCounter.increment(ipNumber);
Packet payload = ipV6Packet.getPayload();
if (ipNumber == IpNumber.ICMPV4) {
IcmpPacketProcessor.processIcmpv4Packet(payload, pcapFileSummary, packetInfo, mode);
} else if (ipNumber == IpNumber.ICMPV6) {
IcmpPacketProcessor.processIcmpv6Packet(payload, pcapFileSummary, packetInfo, mode);
} else if (ipNumber == IpNumber.TCP) {
TcpPacketProcessor.processTcpPacket(payload, pcapFileSummary, packetInfo, mode);
} else if (ipNumber == IpNumber.UDP) {
UdpPacketProcessor.processUdpPacket(payload, pcapFileSummary, packetInfo, mode);
} else {
log.trace("Skipping packet: " + payload);
}
} catch (IllegalRawDataException e) {
log.error("Exception occurred while processing a packet. Exception was: " + e);
}
}
示例10: fixPacketLength
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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);
}
}
示例11: handleMouseClickedEvent
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的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);
}
}
}
}
示例12: testEthernetPacketWithoutVlan
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
/**
* Test of buildPacket method, of class TrexEthernetPacket.
*/
@Test
@Parameters({"macSrcAddress", "macDstAddress", "packetLength", "expectedHex"})
public void testEthernetPacketWithoutVlan(String macSrcAddress, String macDstAddress, int packetLength, String expectedHex) throws IOException, IllegalRawDataException {
LOG.info("------------Testing Ethernet packet");
// build ethernet packet
LOG.info("Building Ethernet packet");
AbstractPacket.AbstractBuilder builder = null;
TrexEthernetPacket instance = new TrexEthernetPacket();
instance.setSrcAddr(macSrcAddress);
instance.setDstAddr(macDstAddress);
instance.setLength(packetLength);
instance.buildPacket(builder);
LOG.info("Encoding packet data");
// Encode packet data
String encodedBinaryPacket = packetUtil.getEncodedPacket(instance.getPacket().getRawData());
LOG.info("Decoding packets and returning packet data information");
// Decode and return packet info
PacketInfo packetInfo = packetUtil.getPacketInfoData(encodedBinaryPacket);
LOG.info("Verifying packet data");
// Assert mac src/destination address
Assert.assertEquals(macSrcAddress, packetInfo.getSrcMac(), "Invalid MAC source address. ");
Assert.assertEquals(macDstAddress, packetInfo.getDestMac(), "Invalid MAC destination address. ");
// Verify packet length
Packet packet = packetUtil.getPacketFromEncodedString(encodedBinaryPacket);
Assert.assertEquals(packetLength, packetUtil.getPacketLength(packet), "Invalid Packet length. ");
// Verify packet data
String packetHex = DatatypeConverter.printHexBinary(packet.getRawData());
Assert.assertEquals(expectedHex.toLowerCase(), packetHex.toLowerCase(), "Invalid Packet hex. ");
}
示例13: handle
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
@Override
public void handle(byte[] payload, byte[] header, Dot11MetaInformation meta) throws IllegalRawDataException {
tick();
Dot11ManagementFrame disassociationRequest = Dot11ManagementFrame.newPacket(payload, 0, payload.length);
String destination = "";
if(disassociationRequest.getHeader().getAddress1() != null) {
destination = disassociationRequest.getHeader().getAddress1().toString();
}
String transmitter = "";
if(disassociationRequest.getHeader().getAddress2() != null) {
transmitter = disassociationRequest.getHeader().getAddress2().toString();
}
// Reason.
short reasonCode = Dot11LeavingReason.extract(payload, header);
String reasonString = Dot11LeavingReason.lookup(reasonCode);
String message = transmitter + " is disassociating from " + destination + " (" + reasonString + ")";
nzyme.notify(
new Notification(message, meta.getChannel())
.addField(FieldNames.TRANSMITTER, transmitter)
.addField(FieldNames.DESTINATION, destination)
.addField(FieldNames.REASON_CODE, reasonCode)
.addField(FieldNames.REASON_STRING, reasonString)
.addField(FieldNames.SUBTYPE, "disassoc"),
meta
);
LOG.debug(message);
}
示例14: newPacket
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
public static Dot11ManagementFrame newPacket(byte[] rawData, int offset, int length) throws IllegalRawDataException {
ByteArrays.validateBounds(rawData, offset, length);
Dot11ManagementFrame.Dot11ManagementFrameHeader h = new Dot11ManagementFrame.Dot11ManagementFrameHeader(rawData, offset, length);
return new Dot11ManagementFrame(rawData, offset, length, h);
}
示例15: Dot11ManagementFrameHeader
import org.pcap4j.packet.IllegalRawDataException; //导入依赖的package包/类
private Dot11ManagementFrameHeader(byte[] rawData, int offset, int length) throws IllegalRawDataException {
super(rawData, offset, length);
}