snowyli_1989
snowyli_1989
采纳率100%
2017-11-28 10:40 阅读 2.2k

python 嗅探器报错[Errno 10013]

import socket
import os
host = "192.168.10.147"

if os.name == 'nt':
socket_protocol = socket.IPPROTO_IP
else:
socket_protocol = socket.IPPROTO_ICMP
sniffer = socket.socket(socket.AF_INET,socket.SOCK_RAW,socket_protocol)
sniffer.bind((host,9999))
sniffer.setsockopt(socket.IPPROTO_IP,socket.IP_HDRINCL, 1)_

if os.name == "nt":
sniffer.ioctl(socket.SIO_RCVALL,socket.RCVALL_ON)

print sniffer.recvfrom(65565)

if os.name == 'nt':
sniffer.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)

运行结果:
Traceback (most recent call last):
0
File "C:/Users/Think/PycharmProjects/Test/sniffer.py", line 10, in
sniffer = socket.socket(socket.AF_INET,socket.SOCK_RAW,socket_protocol)
File "C:\Python27\lib\socket.py", line 191, in init
_sock = _realsocket(family, type, proto)
socket.error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions
不是端口的问题,在获取sniffer实例的时候就已经异常了。是操作权限的问题吗?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    oyljerry oyljerry 2017-11-28 11:07

    你这使用的是底层套接字,需要用root权限,或者管理员权限执行你的py脚本

    点赞 1 评论 复制链接分享

相关推荐