Netcat 命令行问题

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

我不知道为什么

~ $echo stats | nc -vv 10.251.170.80 11211
Connection to 10.251.170.80 11211 port [tcp/*] succeeded!
~ $

只是失败了。

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

CR/LF 有问题吗?

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

~ $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.

系统是fedora 9。

答案1

这对于我在 Debian 上使用 nc.openbsd 和 nc.traditional 都是有效的:

echo -e "stats\nquit" | nc 10.251.170.80  11211

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

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

答案2

我倾向于使用如下的语句:

# (echo stats ; sleep 0.1) | netcat 10.251.170.80 11211

这似乎可以使连接保持足够长的时间来获得答复。

答案3

没有发送换行符?

尝试一下:〜$ echo -e'stats \ n'| nc -vv 10.251.170.80 11211

希望这可以帮助。

答案4

我遇到了同样的问题吉尔曼德。唯一对我有用的@d5ve 睡眠解决方案:

(echo status; sleep 0.1) | nc -w1 locahost 4730

相关内容