How Do I Use Raw Socket in Python?
I see the following code is used to send raw packet.
s = socket(AF_PACKET, SOCK_RAW)
s.bind(("eth1", 0))
...
s.send(dst_addr+src_addr+ethertype+payload+checksum)
But when I try it on Mac, I see this. I am not sure what is the appropriate way to send a raw packet on MacOS. Could anybody let me know?
NameError: name 'AF_PACKET' is not defined
Here is what is shown on help page of macOS. Is any of them appropriate?
| AF_APPLETALK = <AddressFamily.AF_APPLETALK: 16>
|
| AF_INET = <AddressFamily.AF_INET: 2>
|
| AF_INET6 = <AddressFamily.AF_INET6: 30>
|
| AF_IPX = <AddressFamily.AF_IPX: 23>
|
| AF_LINK = <AddressFamily.AF_LINK: 18>
|
| AF_ROUTE = <AddressFamily.AF_ROUTE: 17>
|
| AF_SNA = <AddressFamily.AF_SNA: 11>
|
| AF_SYSTEM = <AddressFamily.AF_SYSTEM: 32>
|
| AF_UNIX = <AddressFamily.AF_UNIX: 1>
|
| AF_UNSPEC = <AddressFamily.AF_UNSPEC: 0>