![](/img/trans.png)
[英]Email whois details on user login using mailx - whois output format not working using sed
[英]How to format WHOIS response
我需要實現一個“whois”服務,它將監聽whois查詢(whois -h)並將使用phpipam API的信息進行響應。 我正在使用啟動腳本的xinetd在端口43上進行偵聽。 我的問題是,當我從服務器發送響應時,服務器在第一個新行之后,重置連接。 出於測試目的,我只是嘗試發送兩條回波線,結果是相同的。
腳本:
#!/bin/bash
echo "One"
echo "Two"
lsof的:
# lsof -i | grep whois
xinetd 17696 root 6u IPv4 91809 0t0 TCP *:whois (LISTEN)
whois查詢(來自客戶端):
# whois -h 192.168.4.129 44.44.44.44
One
fgets: Connection reset by peer
tcpdump的:
# tcpdump -n -i any -X port 43
16:34:01.162440 IP 192.168.4.128.49374 > 192.168.4.129.nicname: Flags [S], seq 1949234703, win 29200, options [mss 1460,sackOK,TS val 337480796 ecr 0,nop,wscale 7], length 0
0x0000: 4500 003c 7a53 4000 4006 3617 c0a8 0480 E..<zS@.@.6.....
0x0010: c0a8 0481 c0de 002b 742e f60f 0000 0000 .......+t.......
0x0020: a002 7210 8a80 0000 0204 05b4 0402 080a ..r.............
0x0030: 141d 8c5c 0000 0000 0103 0307 0000 0000 ...\............
0x0040: 0000 0000 0000 0000 0000 0000 ............
16:34:01.162916 IP 192.168.4.129.nicname > 192.168.4.128.49374: Flags [S.], seq 3654394026, ack 1949234704, win 28960, options [mss 1460,sackOK,TS val 25631110 ecr 337480796,nop,wscale 7], length 0
0x0000: 4500 003c 0000 4000 4006 b06a c0a8 0481 E..<..@.@..j....
0x0010: c0a8 0480 002b c0de d9d1 a0aa 742e f610 .....+......t...
0x0020: a012 7120 eb31 0000 0204 05b4 0402 080a ..q..1..........
0x0030: 0187 1986 141d 8c5c 0103 0307 0000 0000 .......\........
0x0040: 0000 0000 0000 0000 0000 0000 ............
16:34:01.162946 IP 192.168.4.128.49374 > 192.168.4.129.nicname: Flags [.], ack 1, win 229, options [nop,nop,TS val 337480797 ecr 25631110], length 0
0x0000: 4500 0034 7a54 4000 4006 361e c0a8 0480 E..4zT@.@.6.....
0x0010: c0a8 0481 c0de 002b 742e f610 d9d1 a0ab .......+t.......
0x0020: 8010 00e5 8a78 0000 0101 080a 141d 8c5d .....x.........]
0x0030: 0187 1986 0000 0000 0000 0000 0000 0000 ................
0x0040: 0000 0000 ....
16:34:01.163348 IP 192.168.4.128.49374 > 192.168.4.129.nicname: Flags [P.], seq 1:14, ack 1, win 229, options [nop,nop,TS val 337480798 ecr 25631110], length 13
0x0000: 4500 0041 7a55 4000 4006 3610 c0a8 0480 E..AzU@.@.6.....
0x0010: c0a8 0481 c0de 002b 742e f610 d9d1 a0ab .......+t.......
0x0020: 8018 00e5 8a85 0000 0101 080a 141d 8c5e ...............^
0x0030: 0187 1986 3434 2e34 342e 3434 2e34 340d ....44.44.44.44.
0x0040: 0a00 0000 0000 0000 0000 0000 0000 0000 ................
0x0050: 00 .
16:34:01.164122 IP 192.168.4.129.nicname > 192.168.4.128.49374: Flags [.], ack 14, win 227, options [nop,nop,TS val 25631110 ecr 337480798], length 0
0x0000: 4500 0034 b92d 4000 4006 f744 c0a8 0481 E..4.-@.@..D....
0x0010: c0a8 0480 002b c0de d9d1 a0ab 742e f61d .....+......t...
0x0020: 8010 00e3 8a2c 0000 0101 080a 0187 1986 .....,..........
0x0030: 141d 8c5e 0000 0000 0000 0000 0000 0000 ...^............
0x0040: 0000 0000 ....
16:34:01.165523 IP 192.168.4.129.nicname > 192.168.4.128.49374: Flags [P.], seq 1:5, ack 14, win 227, options [nop,nop,TS val 25631110 ecr 337480798], length 4
0x0000: 4500 0038 b92e 4000 4006 f73f c0a8 0481 E..8..@.@..?....
0x0010: c0a8 0480 002b c0de d9d1 a0ab 742e f61d .....+......t...
0x0020: 8018 00e3 d5a7 0000 0101 080a 0187 1986 ................
0x0030: 141d 8c5e 4f6e 650a 0000 0000 0000 0000 ...^One.........
0x0040: 0000 0000 0000 0000 ........
16:34:01.165844 IP 192.168.4.128.49374 > 192.168.4.129.nicname: Flags [.], ack 5, win 229, options [nop,nop,TS val 337480800 ecr 25631110], length 0
0x0000: 4500 0034 7a56 4000 4006 361c c0a8 0480 E..4zV@.@.6.....
0x0010: c0a8 0481 c0de 002b 742e f61d d9d1 a0af .......+t.......
0x0020: 8010 00e5 8a78 0000 0101 080a 141d 8c60 .....x.........`
0x0030: 0187 1986 0000 0000 0000 0000 0000 0000 ................
0x0040: 0000 0000 ....
16:34:01.165914 IP 192.168.4.129.nicname > 192.168.4.128.49374: Flags [R.], seq 5, ack 14, win 227, options [nop,nop,TS val 25631111 ecr 337480798], length 0
0x0000: 4500 0034 b92f 4000 4006 f742 c0a8 0481 E..4./@.@..B....
0x0010: c0a8 0480 002b c0de d9d1 a0af 742e f61d .....+......t...
0x0020: 8014 00e3 8a23 0000 0101 080a 0187 1987 .....#..........
0x0030: 141d 8c5e 0000 0000 0000 0000 0000 0000 ...^............
0x0040: 0000 0000 ....
16:34:01.166350 IP 192.168.4.129.nicname > 192.168.4.128.49374: Flags [R], seq 3654394031, win 0, length 0
0x0000: 4500 0028 826a 4000 4006 2e14 c0a8 0481 E..(.j@.@.......
0x0010: c0a8 0480 002b c0de d9d1 a0af 0000 0000 .....+..........
0x0020: 5004 0000 ea03 0000 0000 0000 0000 0000 P...............
0x0030: 0000 0000 0000 0000 0000 0000 0000 ..............
如果我嘗試使用telnet連接到43,一切正常:
# telnet 192.168.4.129 43
Trying 192.168.4.129...
Connected to 192.168.4.129.
Escape character is '^]'.
One
Two
Connection closed by foreign host.
更新:
像這樣的循環工作正常
while read line; do
echo "One"
echo "Two"
break
done
但是我仍然無法理解為什么它只是通過傳遞兩個回顯線,或者即使我嘗試使用計數器運行while循環:
#!/bin/bash
COUNT=0
while [ $COUNT -lt 5 ]; do
echo The counter is $COUNT
let COUNT=COUNT+1
done
它在第一個周期后停止:
# whois -h 192.168.4.129 44.44.44.44
The counter is 0
fgets: Connection reset by peer
也許你有任何想法,這兩個循環之間的原因/區別是什么?
我的/etc/xinetd.d/whoistest:
service whois
{
port = 43
flags = REUSE
socket_type = stream
protocol = tcp
user = root
wait = no
type = UNLISTED
server = /path/to/shell/script
disable = no
log_type = SYSLOG authpriv
log_on_failure += USERID
}
任何支持將不勝感激。
您需要確保正確配置了xinetd。 您的腳本還需要處理來自whois客戶端的輸入。 這有效:
#!/bin/bash
while read line; do
echo $line
echo "foo"
break
done
這會讀取你的線條,回復它然后回復一些東西。 隨時隨地用echo替換echo $ line。
我必須像這樣配置xinetd才能工作:
service whois
{
port = 43
flags = REUSE
socket_type = stream
protocol = tcp
user = root
wait = no
type = UNLISTED
server = /tmp/w.sh
disable = no
}
希望這可以幫助。 如果您的xinetd服務配置錯誤,它似乎只是丟棄了連接。 如果您的服務器實際上沒有收聽來自客戶端的輸入,您將通過對等錯誤重置連接。
漢努
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.