1

Is there any encapsulation software for constructing network protocol header?

You see my code, I can use struct.pack() to construct a ICMP packet.

import socket
import struct

rawsocket = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.getprotobyname('icmp'))
packet = struct.pack('!BBHHH13s', 8, 0, 0, 1, 0, b'qasdssdehello')
chksum = checksum(packet)

but, I think it is complicated and difficult to use, is there any open source code of encapsulation struct? so I can construct a protocol packet easily.

1 Answer 1

2

Scapy is library that allows construction of network packets, in a high-level way:

Example for ICMP ping:

ICMP Ping Classical ICMP Ping can be emulated using the following command:

ans, unans = sr(IP(dst="192.168.1.1-254")/ICMP())

Information on live hosts can be collected with the following request:

ans.summary(lambda s,r: r.sprintf("%IP.src% is alive") )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.