Netcat: Difference between revisions

From wikinotes
No edit summary
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
NetCat is a very useul tool for sending/receiving messages over TCP.
netcat is a tool for using and testing TCP.
I use it ''almost-daily'' to test daemons, servers, connections, etc.
I believe technically it is slowly being replaced by '''ss''', which I still
need to read up on.  


It's syntax varies slightly from platform to platform, but it's man-page is
{{ NOTE |
very comprehensive and helpful.
netcat has been superceeded by [[ss]] }}


= Install =
<blockquote>
<syntaxhighlight lang="bash">
pacman -S openbsd-netcat
</syntaxhighlight>
</blockquote><!-- Install -->


<source lang="bash">
= Usage =
<blockquote>
== Common Flags ==
<blockquote>
<syntaxhighlight lang="bash">
nc \
nc \
   -u  # send udp packets \
   -u  # send udp packets \
   -v  # verbose \
   -v  # verbose \
   -z  # check if reachable \
   -z  # check if reachable \
</source>
</syntaxhighlight>
</blockquote><!-- Common Flags -->


<source lang="bash">
== Port Testing ==
<blockquote>
<syntaxhighlight lang="bash">
nc -vz    x.x.x.x 80                      # ipv4 confirm port 80 open
nc -6 -vz xxxx:xxxx:xxx:xx::xxx::xxxx 80  # ipv6 confirm port 80 open
</syntaxhighlight>
</blockquote><!-- Port Testing -->
 
== Listen/Send on Port ==
<blockquote>
<syntaxhighlight lang="bash">
nc -l -p 6001                    # Listen to port 6001 on localhost
nc -l -p 6001                    # Listen to port 6001 on localhost


echo "hello" | nc 127.0.0.1 6001  # Send test 'hello' to port 6001 on localhost
echo "hello" | nc 127.0.0.1 6001  # Send test 'hello' to port 6001 on localhost
</source>
</syntaxhighlight>
</blockquote><!-- Listen/Send on Port -->


<source lang="bash">
== Listen/Send on FIFO ==
nc -z domain.com 443  # check errorcode to see if connection was possible
<blockquote>
</source>
<syntaxhighlight lang="bash">
mkfifo /var/temp.sock
nc -U /var/temp.sock        # listen on fifo
</syntaxhighlight>
</blockquote><!-- Listen/Send on sockfile -->
</blockquote><!-- Usage -->

Latest revision as of 03:15, 8 August 2021

netcat is a tool for using and testing TCP.

NOTE:

netcat has been superceeded by ss

Install

pacman -S openbsd-netcat

Usage

Common Flags

nc \
  -u  # send udp packets \
  -v  # verbose \
  -z  # check if reachable \

Port Testing

nc -vz    x.x.x.x 80                      # ipv4 confirm port 80 open
nc -6 -vz xxxx:xxxx:xxx:xx::xxx::xxxx 80  # ipv6 confirm port 80 open

Listen/Send on Port

nc -l -p 6001                     # Listen to port 6001 on localhost

echo "hello" | nc 127.0.0.1 6001  # Send test 'hello' to port 6001 on localhost

Listen/Send on FIFO

mkfifo /var/temp.sock
nc -U /var/temp.sock         # listen on fifo