Reputation: 11
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
Upvotes: 1
Views: 1524
Reputation: 25569
Try running your script as a privileged user. The root
user on Linux would be appropriate.
Upvotes: 1