Send a binary file (line by line) to a socket server with Netcat

前端 未结 2 1670
悲哀的现实
悲哀的现实 2021-01-16 04:34

As a spin off to this Stack Overflow question I want to archieve the same except for a couple of tweaks.

I want to connect to a host, send a binary file, line by lin

2条回答
  •  逝去的感伤
    2021-01-16 05:02

    You can achieve it in two steps:

    1) You need to start nc with a named pipe (fifo) as its input:

    mkfifo /tmp/fifoIn; cat /tmp/fifoIn | nc localhost 2222 &
    

    2) Send your data from file input.txt, line by line with 2 sec delay:

    cat input.txt | while read line; do echo $line; sleep 2; done > /tmp/fifoIn
    

    I've tested it with this "server" (I'm using openbsd netcat syntax):

    nc -l localhost 2222
    

提交回复
热议问题