-py2.7.rarThe following code shows how to use Scapy to complete pcap reading and writing, and provides a picklablepacket class for solving the problem of scapy parsing packet cannot be serialized, the code is as follows:Importscapy fromScapy.allImport* fromScapy.utilsImportPcapreader, PcapwriterImportGzip,zlib,cpickleclassPicklablepacket:" "A container for scapy packets so can be pickled (in contrast to scapy pakcets themselves)" " def __init__(sel
This is a simple analysis of their own pcap file, easy to read Pcap file, we refer to the use of the bar
Copy Code code as follows:
InputStream is = DataParser.class.getClassLoader (). getResourceAsStream ("Baidu_cdr.pcap");
Preface
The data structure has already been defined, so it's time to formally parse the Pcap file.Note: The following only the core code, the project all the code will be at the end of the article to give the download link Resolution pcap file
1 Read the entire Pcap
packet sent by the client
PSH (1 bit): Push function, request to push buffered data to the receiving application
RST (1 bit): Reset connection
SYN (1 bit): Sync serial number. This flag should be set only for the first packet sent from each end. Some other flags and fields change meaning according to this flag, some only work when set 1 o'clock, while others are only valid at 0 o'clock
FIN (1 bit): Last packet from sender
Window size (BITS): The size of the receive
Pcap is a data packet capture library, which is used by many software as a data packet capture tool. Wireshark also uses the pcap library to capture data packets. The packets captured by pcap are not the original network byte streams, but are assembled to form a new data format.The file format of a data packet captured
HTTP packets in the PCAP package can be easily parsed using scapy, scapy_httpScapy_http can be downloaded in https://github.com/invernizzi/scapy-http, the address is also given a simple example program, according to this sample program I modified an output PCAP packet in the source destination address of the HTTP packet, The payload applet is as follows:where P is a packet, scapy_http divides it into:Ethern
The following describes the default *. pcap file storage format of ethereal.
Description of each field in the pcap File Header 24B:Magic: 4b: 0x1a 2B 3C 4d: used to mark the start of the file Major: 2b, 0x02 00: The main version number of the current
The pcap file format is the format in which BPF saves the original data packets. Many software applications are used, such as tcpdump and Wireshark. Understanding the pcap format can enhance understanding of the original data packets, you can also manually construct any data packet for testing.
The pcap
Pcap File Format
Classification: Comprehensive Technology
Transfer http://songwensheng.javaeye.com/blog/674686
Pcap File Format: The pcap file format is the format in which bpf saves the original data packet. Many software appl
pcap_open () function.Snaplen. For exampleSnaplen= 65535, the four bytes become FF 00.
Then, the network type is recorded in 4 bytes. For example, 1 in decimal format indicates Ethernet, 6 indicates the ring-based network, and 15 indicates the hardware format of Frame Relay. Generally, in an Ethernet environment, the four bytes are 01 00 00.
The above fields are part of the file header, followed by data packets. Each packet has a corresponding 16-
.
For definitions, see http :\\
3. Block length (16 bit)
The block length includes chunk type, Chunk flags, Chunk length, and Chunk value.
4. Block Value (variable length)
The block value content transmits the actual information in the block. The content is determined by the message block type. The length of the block value is not long.Sctp struct Definition
// Sctp header typedef struct _ sctp_header {_ int16 srcport; _ int16 dstport; _ int32 ivertag; _ int32 ichecksum;} _ sctpheader; // chunk
Pcap file format Analysis
I. Basic Format:File header data packet ......
Ii. File Header structure:Sturct pcap_file_header {DWORD magic; Word version_major; Word version_minor; DWORD thiszone; DWORD sigfigs; DWORD snaplen; DWORD linktype;} Description: 1. identifier: 32-bit, the value of this flag is 0xa1b2c3d4 in hexadecimal notation. A 32-bit magic number, the
Main content:1. Initial file operation2. Read-only (R,RB)3. Write only (W,WB)4. Append (A, AB)5. Read and write (r+)6. Write-read (w+)7. Additional write read (A +)8. Other methods of operation9. File modification and another wa
About the exception-breaking error when you read the entire file using file ()! I am now using PHP 4.03pl1 to read the entire file using file () when manipulating the text data file, an
File type, C language file read/write, File Buffer, file opening method, file operation functionFile types include stream files and device files. device files such as VGA interfaces, serial ports, USB ports, network ports, and ser
Open the file and add new data at any time.
File *fp;if((fp=fopen("data.txt","a"))==NULL){printf("Create File failure"); exit(1);}fprintf(fp,"[%d, %d]\n", x, y);fclose(fp);
Cyclic operations store a lot of data as follows:
[29, 35][29, 33][30, 34][29, 33][29, 34][29, 34][29, 34][28, 33][30, 34][30, 34][29, 33][28, 33][29, 33][29, 33][29, 34][29, 33]
The pro
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.