Netcat 命令行问题

zuz*_*zur 6 linux command-line-interface netcat

我正在尝试memcached使用netcat.

~ $nc 10.251.170.80 11211
stats
STAT pid 27508
STAT uptime 7940345
STAT time 1262949310
STAT version 1.2.4
STAT pointer_size 64
STAT rusage_user 1389.962693
STAT rusage_system 4857.247586
STAT curr_items 9154565
STAT total_items 615722800
STAT bytes 1994844049
STAT curr_connections 62
STAT total_connections 6263004
STAT connection_structures 148
STAT cmd_get 1925983531
STAT cmd_set 615722800
STAT get_hits 1334407705
STAT get_misses 591575826
STAT evictions 7125864
STAT bytes_read 454794886199
STAT bytes_written 176758890326
STAT limit_maxbytes 2147483648
STAT threads 4
END
Run Code Online (Sandbox Code Playgroud)

我不明白为什么

~ $echo stats | nc -vv 10.251.170.80 11211
Connection to 10.251.170.80 11211 port [tcp/*] succeeded!
~ $
Run Code Online (Sandbox Code Playgroud)

只是失败了。

nc 没有正确读取 stdin 有什么技巧吗?

CR/LF 有问题吗?

我一直在尝试与输入(-C)相关的每个 nc 命令行选项

~ $echo $SHELL
/bin/bash
~ $bash --version
GNU bash, version 3.2.33(1)-release (i386-redhat-linux-gnu)
Copyright (C) 2007 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)

系统是fedora 9。

Jus*_*tin 3

这对我在 debian 上使用 nc.openbsd 和 nc.traditional 有效:

echo -e "stats\nquit" | nc 10.251.170.80  11211
Run Code Online (Sandbox Code Playgroud)

你的netcat似乎正在关闭stdin上EOF上的连接并且不等待输出..你可以尝试-q 1左右..

-q 秒 在 stdin 上的 EOF 后,等待指定的秒数,然后退出。如果秒为负数,则永远等待。