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
14
votes
4 answers

Listening on multiple ports?

Can't you listen on a port range with netcat? You can scan a range, but not listen it appears. So only solution is scripting?
OBV
  • 1,169
  • 1
  • 12
  • 25
13
votes
6 answers

Using netcat/cat in a background shell script (How to avoid Stopped (tty input)? )

Abstract: How to run an interactive task in background? Details: I am trying to run this simple script under ash shell (Busybox) as a background task. myscript.sh& However the script stops immediately... [1]+ Stopped (tty input) myscript.sh The…
LovelyVirus
  • 383
  • 1
  • 3
  • 9
13
votes
4 answers

Is sed blocking?

I had the impression sed wasn't blocking, because when I do say: iostat | sed sed processes the data as it arrives, but when I do iostat | sed | netcat Then sed blocks netcat. Am I right?
Robert Gould
  • 68,773
  • 61
  • 187
  • 272
13
votes
4 answers

Send String over netcat connection

I have two virtual machines open, one is listening on the connection, the other connects with nc from a python subprocess call. I want to send just 1 line of text over the connection then close it. I know how to send a file cat cat…
Crizly
  • 971
  • 1
  • 12
  • 33
12
votes
1 answer

When does a broken pipe occur in a TCP stream?

I am trying to write an echo server in Rust. use std::net::{TcpStream, TcpListener}; use std::io::prelude::*; fn main() { let listener = TcpListener::bind("0.0.0.0:8000").unwrap(); for stream in listener.incoming() { let stream =…
codeNoob
  • 313
  • 1
  • 3
  • 11
12
votes
1 answer

Why does OS X allow listening on the same TCP port twice?

I was trying to debug port allocation problems in Jenkins on OS X by listening to certain ports with netcat, which led to some weird results. In a terminal on OS X 10.8.2: $ uname -rs Darwin 12.2.1 $ nc -l 54321 Then in an second terminal: $ nc…
Christopher Orr
  • 110,418
  • 27
  • 198
  • 193
11
votes
2 answers

Ncat "bad file descriptor" error upon client connection

Problem I have been trying to use Ncat to view some TCP traffic on a CentOS virtual box. However, on this particular machine I can't even establish a simple server/client communication. I open a TCP socket as a "server" or listener (forgive me if…
Bryce
  • 197
  • 1
  • 1
  • 13
11
votes
1 answer

Why is netcat unable to receive the second broadcast message?

While experimenting with broadcast messages (on a Debian 8.3 VM running on VirtualBox 5.0.14 on a Windows 7 laptop) I found that netcat (nc) receives only the first broadcast message. It does not receive the second broadcast message. Programs Here…
Susam Pal
  • 32,765
  • 12
  • 81
  • 103
11
votes
3 answers

netcat sending extra "X" UDP packets

Stealing from here I have set up a small Python script which listens on a port and prints out all of the UDP packets it receives: import socket UDP_IP = "127.0.0.1" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET,…
qntm
  • 4,147
  • 4
  • 27
  • 41
11
votes
3 answers

getting "530 5.7.0 Must issue a STARTTLS command first." error when sending mail via netcat

I'm trying to send an email with netcat, this is what i get: ****-MacBook-Pro:~ ***$ nc smtp.gmail.com 25 220 mx.google.com ESMTP h8sm66301168eew.16 - gsmtp Helo gmail.com 250 mx.google.com at your service MAIL FROM: <******@gmail.com> 530 5.7.0…
dod
  • 141
  • 1
  • 1
  • 5
11
votes
1 answer

Socket communication, Java client C server

I am trying to communicate through sockets a Java client and a C server All seems to work fine if I try the server using nc on the command line to connect or if I use nc as a server and connect with my Java client, but when I try to connect Java…
Jebe
  • 135
  • 1
  • 1
  • 9
11
votes
3 answers

nmap says port is closed while nestat says it's listening

This is Ubuntu 12.04 env. I have a TCP service running on port 8020 on the box: My question is: Why port 8020 is not discovered in nmap as an open port while nestat says it's listening? if i run netstat -tuplen Active Internet connections (only…
Shengjie
  • 12,336
  • 29
  • 98
  • 139
10
votes
1 answer

Netcat streaming using UDP

I can get netcat to stream a video using TCP {server} cat [movie].avi | nc [client ip address] 65535 {client} nc -l -p 65535 | mplayer - i have tried using the -u command to send via UDP but this doesn't work {server} cat [movie].avi | nc…
Dan1676
  • 1,685
  • 8
  • 24
  • 35
10
votes
6 answers

linux script with netcat stops working after x hours

I've have to scripts: #!/bin/bash netcat -lk -p 12345 | while read line do match=$(echo $line | grep -c 'Keep-Alive') if [ $match -eq 1 ]; then [start a command] fi done and #!/bin/bash netcat -lk -p 12346 | while read…
Dennis
  • 1,528
  • 2
  • 16
  • 31
10
votes
4 answers

Send text file, line by line, with netcat

I'm trying to send a file, line by line, with the following commands: nc host port < textfile cat textfile | nc host port I've tried with tail and head, but with the same result: the entire file is sent as a unique line. The server is listening…
Possa
  • 2,067
  • 7
  • 20
  • 22
1 2
3
60 61