How to find the port number of any PC? How to find the port number of any PC? unix unix

How to find the port number of any PC?


I don't know the standard, but I say it's not. At least, I don't like to do it like that.

You can check occupied ports by parsing the outputs of programs like netstat and avoid using those. You can also use the method that attempts connecting on one port, and upon failure, tries another port. Unless you're really really unlucky, you should get a valid port on second try.

You should use ports within the ranges of 49152–65535. Ports below 49152 are reserved/registered.


Basically, you can use any port (given sufficient access rights). But server and client have to agree on the port, and it should not be already used by another application.

Hence, many ports are already reserved for special applications. 80 is for HTTP, 22 is for SSH and so on. The file /etc/services gives more detailed information.

Port numbers 0-1023 are called Well Known Ports, numbers 1024-49151 are called Registered Ports (not all of them are, but you get the idea).


If your question is whether you can give any port number to have your server listening to, then you are thinking wrong, TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them, you can use non-privileged ports(ports > 1024). just make sure that any other application is not already using that port (above 1024) using netstat