Python 2 examples taken while learning SPSE
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

18 lines
498 B

#!/usr/bin/python
# -*- coding: utf-8 -*-
import socket
import struct
rawSocket = socket.socket(socket.PF_PACKET, socket.SOCK_RAW, socket.htons(0x0800))
#rawSocket.bind(("eth0", socket.htons(0x0800)))
rawSocket.bind(("enp0s31f6", socket.htons(0x0800)))
# layer 2 message, then data
# src mac / dst mac / eth type
inet_header = struct.pack("!6s6s2s", '\xaa\xaa\xaa\xaa\xaa\xaa', '\xbb\xbb\xbb\xbb\xbb\xbb','\x08\x00') # 14 bytes
print len(inet_header)
rawSocket.send(inet_header + "Anything")