我试图在Mac上用Python编写一个狙击手,但Python的SOCK_RAW在MAC OS X Yosemite上不起作用。我能做什么?
你可以尝试使用这个Python库:rawsocketpy。它适用于Linux Python2和Python3,但尚未在MAC OSx上验证。
#!/usr/bin/env python
from rawsocketpy import RawSocket
sock = RawSocket("wlp2s0", 0xEEFA)
sock.send("some data")
sock.send("personal data", dest="xAAxBBxCCxDDxEExFF")
或服务器形式:
#!/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()
脚本需要超级用户权限。