I\'m trying to create a DHCP Server and the first step is for me to send packets through my ethernet port. I\'m trying to send packets to my Ethernet interface and having an
This example from the docs seems instructive. https://docs.python.org/2/library/socket.html
import socket
# the public network interface
HOST = socket.gethostbyname(socket.gethostname())
# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))
# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
# receive a package
print s.recvfrom(65565)
# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)
I think the key is socket.gethostbyname(socket.gethostname()). "eth0" as used in your example won't be supported on Windows.