Once upon a time I wanted to check if some ports are open. The network I wanted to check was at my office, and when I forwarded some ports on my Mikrotik I wanted to be sure if I did it correctly. So I started to find solution in the internet and I found that netcat can do it:
nc 127.0.0.1 123 < /dev/null; echo $?
for remote host:
nc 18.104.22.168 123< /dev/null; echo $?
After this command you will get an answer 0 or 1.
0 means port is open
1 means port is closed
If you don’t have netcat on your Ubuntu, you can easy install it by command:
sudo apt-get install netcat