I am trying to write a snipper in Python on a Mac, but Python's SOCK_RAW does not work on MAC OS X Yosemite. What can I do?
Asked
Active
Viewed 293 times
1
-
1Can you share your code and the error? – Mureinik Mar 07 '15 at 13:43
-
Maybe you need to run as super user. – User Mar 07 '15 at 17:08
-
https://stackoverflow.com/questions/6878603/strange-raw-socket-on-mac-os-x, this may be help :) – PerterPon Oct 12 '17 at 07:28
1 Answers
0
You can try using this Python library: rawsocketpy. It works on Linux Python2 and Python3 but not validated on MAC OSx.
#!/usr/bin/env python
from rawsocketpy import RawSocket
sock = RawSocket("wlp2s0", 0xEEFA)
sock.send("some data")
sock.send("personal data", dest="\xAA\xBB\xCC\xDD\xEE\xFF")
or the server form:
#!/usr/bin/env python
from rawsocketpy import RawRequestHandler, RawAsyncServerCallback
import time
def callback(handler, server):
print("Testing")
handler.setup()
handler.handle()
handler.finish()
class LongTaskTest(RawRequestHandler):
def handle(self):
time.sleep(1)
print(self.packet)
def finish(self):
print("End")
def setup(self):
print("Begin")
def main():
rs = RawAsyncServerCallback("wlp2s0", 0xEEFA, LongTaskTest, callback)
rs.spin()
if __name__ == '__main__':
main()
The scripts require superuser rights.

Alexis Paques
- 1,885
- 15
- 29