python raw socket: Protocol not supported

后端 未结 3 794
别那么骄傲
别那么骄傲 2021-01-02 10:49

I am trying to open a raw socket with Python under linux.

My simple code:

s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bin         


        
相关标签:
3条回答
  • 2021-01-02 11:06

    Try socket.AF_PACKET instead of socket.AF_INET.

    0 讨论(0)
  • 2021-01-02 11:14

    This runs without error as root:

    #!/usr/local/cpython-3.3/bin/python
    
    import socket as socket_mod
    
    #s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
    socket = socket_mod.socket(socket_mod.AF_PACKET, socket_mod.SOCK_RAW, socket_mod.IPPROTO_IP)
    #socket.bind(('localhost', 5454))
    socket.bind(('lo', 5454))
    
    0 讨论(0)
  • 2021-01-02 11:20

    Try socket.AF_UNIX, it can solve your problem, good luck.

    0 讨论(0)
提交回复
热议问题