Tag Info

Hot answers tagged

6

Unfortunately it's impossible to do with just bash. /dev/tcp/<ip>/<port> virtual files are implemented in the way that bash tries to connect to the specified <ip>:<port> using connect(2) function. In order to create listening socket, it would have to call bind(2) function. You can check this by downloading bash sources and looking at ...


6

Netcat is not a specialized HTTP client. Connecting through a proxy server for Netcat thus means creating a TCP connection through the server, which is why it expects a SOCKS or HTTPS proxy with the -x argument, specified by -X: -X proxy_protocol Requests that nc should use the specified protocol when talking to the proxy server. ...


5

As perl will be installed. perl -MIO::Socket::INET -ne 'BEGIN{$l=IO::Socket::INET->new( LocalPort=>1234,Proto=>"tcp",Listen=>5,ReuseAddr=>1); $l=$l->accept}print $l $_' < ~/.bashrc would work, unless a local firewall doesn't allow incoming connections to 1234. If socat is installed: socat -u - tcp-listen:1234,reuseaddr < ...


5

Background When you're attempting to use nc in this manner it's continuing to keep the TCP port open, waiting for the destination to acknowledge the receiving of the done request. This is highlighted in the TCP article on Wikipedia. TIME-WAIT (either server or client) represents waiting for enough time to pass to be sure the remote TCP received the ...


5

You could use something like this: while true; do nc -lvp 1337 -c "echo -n 'Your IP is: '; grep connect my.ip | cut -d'[' -f 3 | cut -d']' -f 1" 2> my.ip; done nc will be executed in endless loop listening on port 1337 with verbose option that will write information about remote host to stderr. stderr is redirected to file my.ip. Option -c for nc ...


4

I used the -r and -p switch to xxd: $ echo '0006303030304e43' | xxd -r -p | nc -l localhost 8181 Thanks to inspiration from @Gilles answer, here's a perl version: $ echo '0006303030304e43' | perl -e 'print pack "H*", <STDIN>' | nc -l localhost 8181


4

gawk -v 'RS=\03' -v cmd=' socat -u - udp-datagram:239.255.0.1:30001,bind=127.0.0.1' ' {print $0 RT| cmd; close(cmd)}' < file should work as long as there's not more than 8k in between two ^Cs. That runs one socat command per record (records being ^C delimited via the record separator variable), with the record plus the record terminator fed to ...


4

The program on the left side of a pipe does not receive an EOF (which is not a signal) when the right side of the pipeline ends. It gets a SIGPIPE which tells it to terminate. The problem is that you are not reading anything from the pipeline or reading any data from the pipeline. You probably want a while read loop which will read from stdin as long as it's ...


4

Just put the redirection outside the loop. while true; do read_folder process_data sleep 10 done | netcat $ip $port If you need to output to the loop's standard output from inside the loop, divert it through another file descriptor. { while true; do read_folder echo tick >&3 process_data sleep 10 done | ...


4

Here a solution without xxd or perl: If the echo builtin of your shell supports it (bash and zsh do, but not dash), you just need to use the right backslash escapes: echo -ne '\x00\x06\x30\x30\x30\x30\x4e\x43' | nc -l localhost 8181 If you have /bin/echo from GNU coreutils (nearly standard on Linux systems) or from busybox you can use it, too. With sed ...


3

If you have xxd, that's easy: it can convert to and from hexadecimal. echo '0006303030304e43' | xxd -r -p | nc -l localhost 8181 I don't think there's a reasonable (and reasonably fast) way to convert hexadecimal to binary using only POSIX tools. It can be done fairly easy in Perl. The following script converts hexadecimal to binary, ignoring any input ...


3

With: socat tcp-listen:12345,reuseaddr,fork,bind=127.1 socks:218.62.97.105:11.11.11.11:3128,socksport=1080 you will have a socat waiting for TCP connections on port 12345 on the loopback interface, and forward them to 11.11.11.11:3128 by way of the socks server on 218.62.97.105:1080 You can then use that to connect to D: ssh -o ProxyCommand='socat - ...


3

I think I have an answer: when nc tries an IP address that has a server listening on port 22 (which is typically SSH server), it reads the rest of the input and passes it to the server on port 22. The SSH server I have running on my home machines just eats the input. The nc I have (Slackware 13.1 system) has a "-z" option, for "zero I/O". Try nc -z -w 3 ...


3

The problem is that you're using shell redirects to read from and write to the same file. Check p afterwards, it will be empty as well. The shell opens it in read mode, truncating the file, while it's setting up the pipeline before it runs the commands. However, using tee, since it opens the file itself, means that the file isn't truncated until after the ...


2

I had faced with this problem too. The main problem is netcat. It is a great tool, but it closes the connection when one of its connected input or output file descriptors are closed. It doesn't do anything when server is not listening and it exits when the other peer is closed. As long as you setup the server correctly and keep your file descriptors open, it ...


2

cat out | netcat foo.bar.org 4000 > in & I think the problem is that cat will exit as soon as it receives an EOF from the out pipe. And when cat exits, the rest of the pipeline (including netcat) gets terminated as well. Try something like this instead: while true; do cat out; done | netcat foo.bar.org 4000 > in & Thus, cat gets restarted ...


2

I use tsocks for this purpose. It's a wrapper that catches all connects and forwards them according to your tsocks.conf file. For instance: server = 127.0.0.1 server_type = 5 server_port = 1338 Where as you already have a ssh-proxy set on localhost port 1338. Using this method, you can nest connections since the next ssh session running in the tsocks ...


2

Server side: # nc -l -u -p 666 > /tmp/666.txt Other server side's shell: # tail -F /tmp/666.txt | while IFS= read -r line; do echo "$line"; # do what you want. done; Client side: # nc -uv 127.0.0.1 666 #### Print your commands.


2

The command you are running (nc a.k.a. netcat) will listen for input when run with the -l flag. Normally, netcat in listen mode will close when it receives the end-of-file character, but the -k flag prevents that. In other words, netcat won't close until you kill it because of the way you invoked the command. See the man page for more info.


1

I guess it might as well be an answer so it is at least readable: i=0 ; until { nc -p 8140 -av -n 10.X.X.9 909${i} && [ $((i=i+1)) -gt 4 ] } 2>&- do sleep 1 done Truth is, @slm's got a point about nmap - for handling your network and pen-testing it's an indispensable tool and it's definitely worth your while to get ...


1

OK, I dug it down: nohup runs the program with standard input redirected from /dev/null. So the dd command won't get anything from nc and nc probably will fail to write & close itself on first write tried. So first we need to create a named pipe to route the I/O via: mkfifo my.pipe then run dd with input file from the pipe: nohup dd if=./my.pipe ...


1

vlc has a stream feature to redirect video by network. You need execute this command on server: vlc -vvv zzx.rmvb --sout '#std{access=mmsh,mux=asfh,dst=:8080}' And then,you can execute this command on client: mms://server_ip_address:8080 As the above´╝îI use mms/mmsh to redirect video by network. Vlc support other stream methods.For ...


1

The problem here is in your while read message line. read by default terminates on a newline, but you can pass it another character with the -d option. The question to ask is in your LOGXXXX lines, how does the script know when the entry is finished? If you can put a special character at the end then you can use read -d. Otherwise, you could replace the ...


1

I finally copied using a tar pipe. # cd /mnt/sda1/ && tar cf - * | nc 192.168.1.1 2222 # on laptop # cd /mnt/sda5/ && nc -l 2222 | tar x # on desktop Copying was way faster and seemed to work. I wasn't able to boot in Windows 7 thought. I only saw a black screen when booting in it and the recovery partition freezes at Starting Windows. I ...


1

Your original script requires that the connection comes from a host named localhost, but for some reason that filtering is failing. Unusual, because it matches exactly the name listed in the error: invalid connection to [127.0.0.1] from localhost [127.0.0.1] 60038 This command will listen on the localhost network interface (and will ignore requests from ...


1

The analysis of Steven Monday looks good to me: cat returns after your 1st write to out because the fifo is empty. To avoid that, the solution is to keep a process with the fifo opened in write mode, the 1st cat in the example bellow: mkfifo in mkfifo out cat > out & echo $! > out-pid cat out | netcat foo.bar.org 4000 > in & (The out-pid ...


1

If you use bash and pipes, and are looking for an easy and dirty solution, you can try using sleep. You can use this which act like cat but with a pause at each line. while read i; do echo "$i"; sleep 0.01; done. Here is an example at a little less than 100 lines per second. $ time (seq 1 100 | while read i; do echo "$i"; sleep 0.01; done) [...] real ...


1

From FreeBSD's tee manpage: DESCRIPTION The tee utility copies standard input to standard output, making a copy in zero or more files. The output is unbuffered. unbuffered is the cue, Bash (or your shell's) output redirection (> p) is probably buffered, thus causing the different behavior. (I'm sorry I can't be more certain with this, but I take ...


1

May be it breaks that you have any special symbol at the end of 10.175.192.16? You could try to analyze file without 'read' command: HOSTS=`cat a.txt` for host in $HOSTS; do code=`nc -w 3 -z "$host" 22 >& /dev/null; echo $?` if [ "$code" == "0" ]; then echo $host >> reachable.txt else echo $host >> ...


1

People of the future, do not fear. If you've found this question, you've come across a frustrating problem and are looking for a sure-fire solution. Luckily, I have answered this question on a different SE site. It has worked for both the OP and me. It can be found here.



Only top voted, non community-wiki answers of a minimum length are eligible