-
Download and unpack the asset for your platform from the release page.
-
Open a terminal and run the program.
# Linux
al@linux ~ $ ./testnc github.com:443
OK :: 10.0.1.10 -> github.com:443 -> 140.82.121.4:443
al@linux ~ $ ./testnc github.com:8080
BAD :: github.com:8080 -> 140.82.121.4:8080
# Windows
PS C:\Users\al> .\testnc.exe --help
A simple program to test TCP network connectivity
Usage: testnc.exe [OPTIONS] [CONNECTIONS]...
Arguments:
[CONNECTIONS]... One or more connection strings in the form 'host:port'
Options:
-t, --timeout <TIMEOUT> Timeout for each connection in seconds [default: 1]
-f, --file <FILE> File with connection strings in the form 'host:port' separated by newlines
-h, --help Print help (see more with '--help')
-V, --version Print version
To test multiple connections, use command-line arguments:
al@linux ~ $ ./testnc github.com:443 github.com:22
OK :: 10.0.1.10 -> github.com:443 -> 140.82.121.3:443
OK :: 10.0.1.10 -> github.com:22 -> 140.82.121.3:22
Or use a text file with a list of connections:
al@linux ~ $ cat ./connections.txt
github.com:22
github.com:443
github.com:8080
al@linux ~ $ ./testnc --file connections.txt
OK :: 10.0.1.10 -> github.com:22 -> 140.82.121.4:22
OK :: 10.0.1.10 -> github.com:443 -> 140.82.121.4:443
BAD :: github.com:8080 -> 140.82.121.4:8080
Pass multiple files like this:
al@linux ~ $ ./testnc --file connections.txt --file more-connections.txt
You can annotate your connection list with #
comment lines:
al@linux ~ $ cat ./connections.txt
# Github
github.com:22
github.com:443
# This should fail:
github.com:8080
al@linux ~ $ ./testnc --file connections.txt
# Github
OK :: 10.0.1.10 -> github.com:22 -> 140.82.121.3:22
OK :: 10.0.1.10 -> github.com:443 -> 140.82.121.3:443
# This should fail:
BAD :: github.com:8080 -> 140.82.121.3:8080
You can let Ansible run this program on different hosts and collect the results.
Copy the program to a location where Ansible can find it, e.g. next to a playbook.
- name: Example play
hosts: all
tasks:
- name: testnc - copy, run and then remove binary
ansible.builtin.script: testnc {{ connections | join(" ") }}
changed_when: false # the script module always reports 'changed' on return code zero.
register: testnc_result
vars:
connections:
- github.com:22
- github.com:443
- github.com:8080
- name: testnc - print results
ansible.builtin.debug:
var: testnc_result.stdout_lines