On Fri, Feb 10, 2012 at 3:12 PM, daedae11 <daeda...@126.com> wrote: > 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] >
That's very strange, because when I run it, the interpreter shows the following error: Traceback (most recent call last): File "C:/Users/hugo/Downloads/test.py", line 7, in <module> s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP) File "C:\Python27\lib\socket.py", line 187, in __init__ _sock = _realsocket(family, type, proto) error: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions >>> Which is identical to yours, but includes a helpful message telling you what is wrong. Did you not get that message, or did you just paste it wrong? In any case, Walter got you the solution. HTH, Hugo _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor