Created
August 27, 2017 13:21
-
-
Save povilasb/22f9415c1d56cd90cf96ba53f8a3f9e1 to your computer and use it in GitHub Desktop.
Send IP packets with Linux raw sockets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from pypacker.layer3.ip import IP | |
from pypacker.layer3.icmp import ICMP | |
def main() -> None: | |
sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) | |
ip = IP(src_s='192.168.0.103', dst_s='8.8.8.8', p=1) +\ | |
ICMP(type=8) +\ | |
ICMP.Echo(id=123, seq=1, body_bytes=b'povilas-test') | |
sock.sendto(ip.bin(), ('8.8.8.8', 0)) | |
# Does not work. Might need to put interface to promiscuous mode. | |
resp = sock.recvfrom(4096) | |
print(resp) | |
sock.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment