1

I'm trying to read files with bash tcp socket,

So on one host I do,

nc -l 8888 < /etc/passwd

And on another machine,

echo </dev/tcp/127.0.0.1/8888

But it didn't read the file as expected, I got an empty line.

I know cat < /dev/tcp/xxx/xxxx works, but can I do that without external binaries?

EDIT

So I tried $() syntax,

# echo $(</dev/tcp/127.0.0.1/8888) > file
bash: /dev/tcp/127.0.0.1/8888: No such file or directory
2
  • echo "$(</dev/tcp/127.0.0.1/8888)" ?
    – 123
    Commented Apr 6, 2016 at 9:39
  • echo doesn't do what you think it does. You probably meant to use cat. Commented Jun 13, 2016 at 4:28

1 Answer 1

2

You can use a while loop:

while IFS= read -r line; do
    printf '%s\n' "$line"
done < /dev/tcp/localhost/8888

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .