1

I am using Python 2.7. I have tried everything and it is not connecting. The error I get is:

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.

I am making a 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
2
  • 3
    Are you running your script as root? Creating raw sockets is usually a privileged operation. Commented Oct 5, 2013 at 17:56
  • You'll have to run this script as an administrator. I'm pretty sure you want to pass icmp as the third argument to socket.socket(). Commented Oct 5, 2013 at 18:14

1 Answer 1

1

Try running your script as a privileged user. The root user on Linux would be appropriate.

Sign up to request clarification or add additional context in comments.

2 Comments

I think they're on Windows, otherwise their script wouldn't be using socket.ioctl.
i am on Windows, sorry

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.