问题原文
原帖链接 · SparedWhisle · CC BY-SA 4.0
Say for some reason, on a Windows system I'm managing, I do not want any application to listen on a certain port, say for example 8000.
The effect would be when a user tries to run an application to listen on that port, for example, python -m http.server 8000, he gets the usual error saying OSError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions. And when he checks if anything is already using that port using a command like netstat -ano|findstr 8000 he wouldn't find anything.
It's kind of like reserving, like saying "no one is allowed to use this port, cause I might need to use it for important business".
How should I go about doing that? Does Windows support this natively? Do I need 3rd party software to achieve this?
已采纳解答
原帖链接 · petitradisgris · CC BY-SA 4.0
You should look at the 'netsh' command-line utility. This will make 'reservation' of ports... Making them unbindable by unprivileged processes.
NETSH list reserved ports on ipv4 > tcp stack:
netsh interface ipv4 show excludedportrange protocol=tcp
NETSH reserve ports (template):
netsh int <ipv4|ipv6> Add excludedportrange [protocol=]tcp|udp [startport=]<integer> [numberofports=]<integer> [[store=]active|persistent]
EXAMPLE: NETSH, reserve port 8000 for ipv4 > tcp, use the command:
netsh int ipv4 add excludedportrange protocol=tcp startport=8000 numberofports=1
By default port reservations are persistent across reboots.
In all case, i suggest you to read the NETSH documentation and related usage and examples links
If the above solution is not working, you may try it :
- windows-server reserve a port range by registry.
- However, if you are running Windows Server 2008, you may experience issue with the functionality and you would need to install HOTFIX or update your system, as explained here.
Hope it helps
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
