All other solutions use netcat to support the network, but you can end this if your bash is fairly recent and compiled with --enable-net-redirections(which, as far as I can tell, all but Debian and Ubuntu; feel free to comment if I have to configure).
Then grepcan do the actual testing. Its return code is a wrapper (0 for success, nonzero for failure), so you will need to invert this, but it bashhandles it just fine.
In a nutshell:
< /dev/tcp/host/port grep -q 'expected value'
echo $(( 1 - $? ))
source
share