代码:
import socket
host, port = "", 3333
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((host, port))
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)
while True:
packet = s.recv(65565)
print(packet)
错误:
C:\Users\Me\PycharmProjects\packets\venv\Scripts\python.exe C:/Users/Me/PycharmProjects/packets/socket_test.py
Traceback (most recent call last):
File "C:/Users/Me/PycharmProjects/packets/socket_test.py", line 4, in <module>
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
File "C:\Users\Me\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 231, in __init__
_socket.socket.__init__(self, family, type, proto, fileno)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
答案 0 :(得分:0)
我正在使用PyCharm /命令提示符/ Git Bash运行脚本。这是一个非常简单的修复程序,过于复杂。
对于要用于运行脚本的程序,请执行以下操作:
通过以管理员身份运行PyCharm,可以解决此问题。对Git Bash和命令提示符执行相同的操作,脚本终于运行了。