Netcat

通過 Netcat 向 Memcached 發送 UDP 數據包

  • March 4, 2018

我正在嘗試stats通過 netcat 將命令發送到 memcached,但是,我沒有從 memcached 得到任何返回…

我試過了

echo "stats" > commands.txt
nc -u 127.0.0.1 11211 < commands.txt

我也試過

echo stats | nc -u 127.0.0.1 11211

根據我在Memcached 文件底部的第1176 行閱讀的內容,發送時的命令可能必須包括

Each UDP datagram contains a simple frame header, followed by data in the
same format as the TCP protocol described above. In the current
implementation, requests must be contained in a single UDP datagram, but
responses may span several datagrams. (The only common requests that would
span multiple datagrams are huge multi-key "get" requests and "set"
requests, both of which are more suitable to TCP transport for reliability
reasons anyway.)

The frame header is 8 bytes long, as follows (all values are 16-bit integers 
in network byte order, high byte first):

0-1 Request ID
2-3 Sequence number
4-5 Total number of datagrams in this message
6-7 Reserved for future use; must be 0

我的問題是,如何stats使用 netcat 通過 udp 將命令發送到 Memcached?

以下工作,您必須指定幀頭

printf '\x00\x00\x00\x00\x00\x01\x00\x00stats\r\n' | nc -u 127.0.0.1 11211

引用自:https://unix.stackexchange.com/questions/428023