I use this command so much when negotiating whether network, and firewalld, rules are configured that I felt obligated to post it. If you need to ping a remote server TCP port then this is the command for you. I have test this on Red Hat Enterprise Linux, since that is what I use at work. It should work on Ubuntu as well.
The command
|
1 |
portping() { python <<<"import socket; socket.setdefaulttimeout(1); socket.socket().connect(('$1', $2))" 2> /dev/null && echo OPEN || echo CLOSED; } |
Usage
portping <ip address> <port>
Example
portping 123.456.789.1 8500