Questions tagged [netcat]

netcat is a command for performing read/write operations on TCP or UDP network connections.

From the official GNU netcat project page:

It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities.

It provides access to the following main features:

  • Outbound and inbound connections, TCP or UDP, to or from any ports.
  • Featured tunneling mode which allows also special tunneling such as UDP to TCP, with the possibility of specifying all network parameters (source port/interface, listening port/interface, and the remote host allowed to connect to the tunnel.
  • Built-in port-scanning capabilities, with randomizer.
  • Advanced usage options, such as buffered send-mode (one line every N seconds), and hexdump (to stderr or to a specified file) of trasmitted and received data.
  • Optional RFC854 telnet codes parser and responder.

SANS has produced a netcat cheat sheet (PDF) with various tips on usage.

911 questions
175
votes
15 answers

Minimal web server using netcat

I'm trying to set up a minimal web server using netcat (nc). When the browser calls up localhost:1500, for instance, it should show the result of a function (date in the example below, but eventually it'll be a python or c program that yields some…
andwagon
  • 1,851
  • 2
  • 12
  • 4
155
votes
6 answers

How to send only one UDP packet with netcat?

I want to send only one short value in a UDP packet, but running the command echo -n "hello" | nc -4u localhost 8000 I can see that the server is getting the hello stuff but I have to press Ctrl+c to quit the netcat command. How can I make it quit…
Janne H
  • 1,573
  • 2
  • 10
  • 6
98
votes
9 answers

access host's ssh tunnel from docker container

Using ubuntu tusty, there is a service running on a remote machine, that I can access via port forwarding through an ssh tunnel from localhost:9999. I have a docker container running. I need to access that remote service via the host's tunnel, from…
npit
  • 2,219
  • 2
  • 19
  • 25
94
votes
12 answers

How to wait for an open port with netcat?

I'm trying to do a custom dockerfile with jenkins on it. I would to wait until port 8080 is open instead of doing an ugly 'sleep 60' with netcat but I'm not very confident with bash scripts and netcat. Here is an example of what i'm trying to…
FXG
  • 1,308
  • 1
  • 12
  • 21
65
votes
5 answers

How to make an HTTP GET request manually with netcat?

So, I have to retrieve temperature from any one of the cities from http://www.rssweather.com/dir/Asia/India. Let's assume I want to retrieve of Kanpur's. How to make an HTTP GET request with Netcat? I'm doing something like this. nc -v…
Avinash Bhawnani
  • 761
  • 1
  • 6
  • 7
58
votes
5 answers

How to make an Echo server with Bash?

How to write a echo server bash script using tools like nc, echo, xargs, etc capable of simultaneously processing requests from multiple clients each with durable connection? The best that I've came up so far is nc -l -p 2000 -c 'xargs -n1…
Roskoto
  • 1,722
  • 1
  • 16
  • 27
49
votes
8 answers

How can I tail a remote file?

I am trying to find a good way to tail a file on a remote host. This is on an internal network of Linux machines. The requirements are: Must be well behaved (no extra process laying around, or continuing output) Cannot require someone's pet Perl…
Frosty
  • 6,213
  • 3
  • 24
  • 20
43
votes
3 answers

Netcat implementation in Python

I found this and am using it as my base, but it wasn't working right out of the box. My goal is also to treat it as a package instead of a command line utility, so my code changes will reflect that. class Netcat: def __init__(self, hostname,…
unholysampler
  • 17,141
  • 7
  • 47
  • 64
40
votes
3 answers

How do I get netcat to accept connections from outside the LAN?

I'm using netcat as a backend to shovel data back and forth for a program I'm making. I tested my program on the local network, and once it worked I thought it would be a matter of simply forwarding a port from my router to have my program work over…
Chris
  • 631
  • 1
  • 5
  • 7
39
votes
7 answers

How to listen for multiple tcp connection using nc

How to create a TCP connection using nc which listens to multiple hosts? nc -l -p 12345
Aman Jain
  • 895
  • 2
  • 10
  • 19
39
votes
3 answers

Bash: Loop until command exit status equals 0

I have a netcat installed on my local machine and a service running on port 25565. Using the command: nc 127.0.0.1 25565 < /dev/null; echo $? Netcat checks if the port is open and returns a 0 if it open, and a 1 if it closed. I am trying to write a…
Snaacky
  • 512
  • 1
  • 6
  • 13
36
votes
4 answers

Strange behaviour of netcat with UDP

I noticed a strange behaviour working with netcat and UDP. I start an instance (instance 1) of netcat that listens on a UDP port: nc -lu -p 10000 So i launch another instance of netcat (instance 2) and try to send datagrams to my process: nc -u…
MirkoBanchi
  • 2,173
  • 5
  • 35
  • 52
33
votes
5 answers

How can I close a netcat connection after a certain character is returned in the response?

We have a very simple tcp messaging script that cats some text to a server port which returns and displays a response. The part of the script we care about looks something like this: cat someFile | netcat somehost 1234 The response the server…
SCdF
  • 57,260
  • 24
  • 77
  • 113
32
votes
1 answer

How to switch to netcat-traditional in Ubuntu?

How do I switch to netcat-traditional in Ubuntu? Whenever I write netcat -h, it appears that I am running netcat-openbsd instead. I'm new to Ubuntu, so exact commands would be helpful.
Nosrettap
  • 10,940
  • 23
  • 85
  • 140
26
votes
2 answers

I am unable to execute netcat command within docker bash terminal?

I am a beginner in docker . I have installed docker-ce in my ubuntu 18.04 machine using commandsudo apt install docker-ce As part of a tutorial , I am trying to establish connection between containers by executing series of below commands. Below…
Mr.Robot
  • 489
  • 2
  • 8
  • 17
1
2 3
60 61