Checking outbound ports with bash script.

I would like to present today very short but useful bash script, which is going to check status of outbound ports on your personal computer or server if you have one. In my case the main reason why I searched for writing this kind of script was inability to connect with my FTP server, which was configured in passive mode. It turns out that my ISP is blocking almost all outbound ports. I think that this can happend to anyone, especially at work when you are connected to somekind of corporate network.

Working of the script is based on tries to connect with the server of webpage Outbound Port Tester with use of netcat program. Connections are going to be espablished on single port or in some range of ports depending on arguments passing by user from command line. In case successfully established connection we can see following output:


on the contrary in case of failed connection we'd see following output:


and here is script which I wrote:

We're starting the script from putting at line 1 so called shebang:"#!" which is some kind of clue which interpreter must be used. At line 6 we got regular expression which allows us to validate port arguments given by the user from command line. Matching port values are from 0-65535. Function called usage is used to print informations how to use the script. Lines 22-29 are responsible for valiadating amount and correctness of arguments passed to the script by the user. In the end at lines 51-60 we got while loop which iterates over given port range and calls netcat command for each iterated port.

For convenience we could create symbolic link to our script with command :


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.