Piping prevents commands from fully executing?
Why is it, that when I pipe a command into another command, the other command doesn't fully execute? Like if I run
echo -e -n "localhost / 0\r\n" | nc localhost 301
or
echo -e -n "localhost / 0\r\n" | nc -w 100s localhost 301
it does not output the response from localhost, or even wait for 100 seconds and timeout, it just exits. Why is this?
Mar 01 ยท 4 months ago
6 Comments โ
๐ค BBSman ยท Mar 01 at 13:56:
`nc` exits immediately when it can't connect to the specified host & port.
๐ asdf [OP] ยท Mar 01 at 14:51:
@BBSman that is irrelevant since "nc localhost 301" does connect.
๐ jsreed5 ยท Mar 01 at 15:57:
What do you see if you run `nc -vz`? nc might be encountering some other error that it's not reporting.
๐ asdf [OP] ยท Mar 01 at 16:07:
@jsreed5 running "nc -vz" by itself outputs the following message:
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: You must specify a host to connect to. QUITTING.
running
echo -e -n "localhost / 0\r\n" | nc -vz localhost 301
does not output anything
Edit: I'm a dumbass, accidentally ran it with a greater than sign instead of a pipe (I just went through my bash history until I found the command so I could add the -vz but I edited the wrong command)
the output from
echo -e -n "localhost / 0\r\n" | nc -vz localhost 301
was actually
Ncat: Version 7.93 ( https://nmap.org/ncat )
Ncat: Connected to ::1:301.
Ncat: 0 bytes sent, 0 bytes received in 0.22 seconds.
It's strange, because when running "nc localhost 301" it does respond, so it shouldn't say "0 bytes received"
๐ clseibold ยท Mar 01 at 21:19:
@asdf Is this connecting to spartan server?
๐ asdf [OP] ยท Mar 02 at 07:10:
@clseibold yes
Source