问题
In this (rather old) article, the author states:
"Port Blocking
Port blocking allows an application to prevent other applications from performing specific binds to the ports within a specified range. When blocking a port range, the application must choose a contiguous range of port numbers that are between the value of the MaxUserPort setting (5000 by default) + 1 and either 49151 (for Windows XP and Windows Server 2003 with no service packs installed) or 65535 (for Windows Server 2003 Service Pack 1). There should be no existing bindings to the ports within the range of blocked ports. Windows Sockets returns the last port number in the blocked range as the handle. When unblocking (removing the block), Windows Sockets unblocks the range that has the same left edge as the unblock request."
The implication I get from reading this is that there is some api an application can use to set/unset this, but I have drawn complete blanks trying to search documentation for any such thing, nor do I recall ever seeing such functionality in my socket programming days.
Is there such a capability in Windows, and if so, pointers to documentation of it will be heartily appreciated!
回答1:
There is no such call in the winsock API itself, but I believe there is in the LSP feature. Another (easy but dirty <3) way is to just bind() to all the ports you want blocked.
回答2:
You can set the range of ports which will be used for dynamic clients (binding to any available socket) on the system by the MaxUserPort registry value (applicable from Vista onwards). The dynamic port range can be set for tcp and udp sockets. More details in the following links :
MaxUserPort
KB929851
So you can set the range (to allow), as per your needs
来源:https://stackoverflow.com/questions/13876701/is-there-a-windows-socket-api-call-option-to-block-a-range-of-ports-%c3%a0-la-so