How should one go about choosing a default TCP/IP

2019-01-16 17:32发布

When developing an app that will listen on a TCP/IP port, how should one go about selecting a default port? Assume that this app will be installed on many computers, and that avoiding port conflicts is desired.

12条回答
女痞
2楼-- · 2019-01-16 18:01

Choosing an unassigned one from the IANA list is usually sufficient, but if you are talking about a commercially-released product, you really should apply to the IANA to get one assigned to you. Note that the process of doing this is simple but slow; the last time I applied for one, it took a year.

查看更多
乱世女痞
3楼-- · 2019-01-16 18:02

The most comprehensive list of official IANA port numbers and non-official port numbers I know is nmap-services.

查看更多
老娘就宠你
4楼-- · 2019-01-16 18:05

First step: look at IANA listing :

There you will see at the tail of the list

"The Dynamic and/or Private Ports are those from 49152 through 65535"

so those would be your better bets, but once you pick one you could always google on it to see if there is a popular enough app that has already "claimed" it

查看更多
甜甜的少女心
5楼-- · 2019-01-16 18:08

Use iana list. Download the csv file from :

https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.csv

and use this shell script for searching for unregistred ports:

for port in {N..M}; do if ! grep -q $port service-names-port-numbers.csv; then echo $port;fi; done;

and put 2 numbers instead of N and M.

查看更多
The star\"
6楼-- · 2019-01-16 18:09

As others mention, check IANA.

Then check your local systems /etc/services to see if there are some custom ports already in use.

And please, don't hardcode it. Make sure it's configurable, someway, somehow -- if for no other reason that you want to be able to have multiple developers using their own localized builds at the same time.

查看更多
我欲成王,谁敢阻挡
7楼-- · 2019-01-16 18:09

Choose a default port that doesn't interfere with the most common daemons and servers. Also make sure that the port number isn't listed as an attack vector for some virus -- some companies have strict policies where they block such ports no matter what. Last but not least, make sure the port number is configurable.

查看更多
登录 后发表回答