0
  • Fresh Python 3.8 Installation
  • Windows 10 1903
  • Using PyCharm
  • Tried port 80, 3333, random ports
  • Not running any KNOWN servers on my machine.
  • Windows Firewall is turned off
  • Antivirus software is turned off
  • netstat -ao does not show any process hogging port 80 or any tested port.
  • Telnet is not installed by default in Windows 10. This should not be mentioned as a possible answer?

Code:

import socket

host, port = "", 3333
s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
s.bind((host, port))
s.setsockopt(socket.IPPROTO_IP, socket.IP_HDRINCL, 1)
s.ioctl(socket.SIO_RCVALL, socket.RCVALL_ON)

while True:
    packet = s.recv(65565)
    print(packet)

Error:

C:\Users\Me\PycharmProjects\packets\venv\Scripts\python.exe C:/Users/Me/PycharmProjects/packets/socket_test.py
Traceback (most recent call last):
  File "C:/Users/Me/PycharmProjects/packets/socket_test.py", line 4, in <module>
    s = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_IP)
  File "C:\Users\Me\AppData\Local\Programs\Python\Python38-32\lib\socket.py", line 231, in __init__
    _socket.socket.__init__(self, family, type, proto, fileno)
OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
Bret Hagen
  • 88
  • 5
  • May be related to [this question](https://stackoverflow.com/questions/15619921/an-attempt-was-made-to-access-a-socket-in-a-way-forbidden-by-its-access-permissi) involving SQL server 2008 and sockets. – Ross Jacobs Apr 26 '20 at 23:52
  • Answers to similar questions indicate a problem with Windows Firewall settings being too strict. – Ross Jacobs Apr 26 '20 at 23:54
  • @RossJacobs Currently not running any SQL server on machine. Not related to this issue I believe. Additionally, Windows Firewall is off and all antivirus is off. – Bret Hagen Apr 27 '20 at 02:35
  • Another post that has some insight: https://stackoverflow.com/questions/2778840/socket-error-errno-10013-an-attempt-was-made-to-access-a-socket-in-a-way-forb – befunkt Apr 27 '20 at 02:44
  • Can you run the module http.server from a command prompt? python -m http.server 80 – befunkt Apr 27 '20 at 03:00
  • It's similar in that these are programs on windows attempting to access sockets and running into the same errors. You've edited your question to include that Windows Firewall is turned off, so that's helpful. – Ross Jacobs Apr 27 '20 at 03:21

1 Answers1

0

I am using PyCharm / Command Prompt / Git Bash to run scripts. It was an extremely easy fix that was over complicated.

For what ever program you're using to run the script do the following:

  1. Right click the application.
  2. Run as administrator.

By running PyCharm as administrator I was able to get past this issue. Doing the same for Git Bash and Command Prompt the script finally ran.

Bret Hagen
  • 88
  • 5