davesc63 / GeoPort

GeoPort: Your Location, Anywhere! The iOS location simulator
https://geoport.me
GNU General Public License v3.0
102 stars 9 forks source link

Doc Request - How to debug "An attempt was made to access a socket in a way forbidden by its access permissions" #48

Closed MTDickens closed 1 month ago

MTDickens commented 1 month ago

I think many WSL2 user might encounter this bug. This debug tutorial is from XX-net. The tutorial is written in Chinese, and I translated it into English via Chatgpt.

BUG

English: An attempt was made to access a socket in a way forbidden by its access permissions 中文: 你的主机中的软件中止了一个已建立的连接

Reason

This is because port 54321 is occupied. However, using netstat -aon | findstr cannot locate the port.

The reason is that the Hyper-V feature is enabled on this machine. This feature is related to Docker or virtual machines, and WSL2 also requires this feature to be enabled. Windows by default assigns certain port ranges to Hyper-V, making them reserved ports, so we cannot use this port.

Viewing the Default Dynamic TCP Port Range in Windows

You can view it using the command:

netsh int ipv4 show dynamicport tcp

Viewing the Reserved Port Range

You can view the reserved port range using the command:

netsh interface ipv4 show excludedportrange protocol=tcp

Sometimes ports like 1080, 8087, 8085 might be included in this range.

Resolving the Issue

Run CMD as an administrator, and set the dynamic port range so that the reserved port range avoids the ports we need.

netsh int ipv4 set dynamicport tcp start=54322 num=12214
netsh int ipv4 set dynamicport udp start=54322 num=12214

Then restart your computer.

davesc63 commented 1 month ago

Unsure what this relates to but as part of the recent release notes, if you need a custom port to be used, you can use the —port cli arg