1

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?

Mureinik
  • 297,002
  • 52
  • 306
  • 350

1 Answers1

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