[Tutor] Question about an example in Python doc

daedae11 daedae11 at 126.com
Fri Feb 10 15:12:49 CET 2012


The example is the third example in (Python2.7's doc)->(Python Library Reference)->17.2.2.
The code of the example is:

import socket

# the public network interface
HOST = socket.gethostbyname(socket.gethostname())

# create a raw socket and bind it to the public interface
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((HOST, 0))

# Include IP headers
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)

# receive all packages
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)

# receive a package
print s.recvfrom(65565)

# disabled promiscuous mode
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_OFF)


However, when I run it, the interpreter show the following error:

Traceback (most recent call last):
  File "E:\c language\Eclipse\example\src\sniffer.py", line 12, in <module>
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
  File "D:\Python27\lib\socket.py", line 187, in __init__
    _sock = _realsocket(family, type, proto)
socket.error: [Errno 10013] 

What's the matter?




daedae11
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120210/116437e1/attachment.html>


More information about the Tutor mailing list