I am using this Python code to listen to a port on my Windows 10 system:
import socket for port in (50059, 50060, 50959, 50960): try: print(socket.socket(socket.AF_INET, socket.SOCK_STREAM).bind(('localhost', port))) except OSError as e: print(e)
However, it prints
None [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions None
meaning that I cannot access ports 50060 and 50959. I experimented further and confirmed that I cannot listen to any port in the range 50060-50959.
Update: After upgrading to Windows 10, 2004, it's port range 50060-59708 that is blocked somehow.
I would like to listen to port 50323, which falls into this range (in both cases).
I have tried
netstat -aonq to find the culprit, but without success
C:\Users\bers>netstat -aon | grep :50 TCP 0.0.0.0:5040 0.0.0.0:0 LISTENING 8008 (Connected Devices Platform Service) TCP 10.0.0.20:50985 22.214.171.124:443 ESTABLISHED 5208 (Windows Push Notifications System Service) UDP 0.0.0.0:500 *:* 4936 UDP 0.0.0.0:5050 *:* 8008 UDP [::]:500 *:* 4936
Nothing else seems to be listening in this range. So why can't I?
50060-50959 is exactly 900 ports - I am sure this is no coincidence. (Update: Well, I was - it's 9649 ports on Windows 10, 2004.)
I have checked
- 10013 No socket could be created error, however nothing is listening on that port
- TCP/UDP ports that cannot be bound (permission error), but don't show up in netstat
- Determining what process has bound a port (without listening) on Windows
This means I have also tried
netstat -q, see above,
resmon.exe, and disabled Internet Connection Sharing (ICS).