[colug-432] nc replacement in RHEL7?

bob at disclosed.org bob at disclosed.org
Thu May 28 17:26:33 EDT 2015


On Thu, May 28, 2015, at 05:04 PM, Greg Sidelinger wrote:
> Personally I like to use "echo > /dev/tcp/hostname/port".  I think
> this is a feature of bash.
> 
> $ echo > /dev/tcp/127.0.0.1/80
> $ echo $?
> 0
> $ echo > /dev/tcp/127.0.0.1/90
> -bash: connect: Connection refused
> -bash: /dev/tcp/127.0.0.1/90: Connection refused
> $ echo $?
> 1

Yar, similarly, I'd never used -z before, but I pipe an empty string to
'nc' to cause it to open the connection, send no data, and close the
connection.  Failure to connect returns an error code. 

[jewellb:~]$ echo "" | nc 127.0.0.1 80   
[jewellb:~]$ echo $?                     
0
[jewellb:~]$ echo "" | nc 127.0.0.1 1337 
[jewellb:~]$ echo $?                    
1


More information about the colug-432 mailing list