1

我正在使用 Python 2.7。我已经尝试了一切,但它没有连接。我得到的错误是:

Socket could not be created. Error Code : 10013 Message An attempt was 
    made to access a socket in a way forbidden by its access permissions.

我正在ping。

def doOnePing(destAddr, timeout):
    icmp = socket.getprotobyname("icmp")
    # SOCK_RAW is a powerful socket type. For more details see: 
    # http://sock-raw.org/papers/sock_raw
    # Fill in start
    # Create Socket here
    try:
        #mySocket = socket.socket(2, 3, 1)
        # the public network interface
        HOST = socket.gethostbyname(socket.gethostname())

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

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

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

        # receive a package
        print mySocket.recvfrom(65565)

        print ('Connected by', destAddr)
    except socket.error , msg:
        print ('Socket could not be created. Error Code : ' + str(msg[0]) + 
              ' Message ' + msg[1])
    #Fill in end
4

1 回答 1

1

尝试以特权用户身份运行您的脚本。Linux 上的root用户将是合适的。

于 2013-10-05T18:13:30.440 回答