telnet 连接的脚本输出

telnet 连接的脚本输出

另一个 whois 问题,我是否可以将 telnet 连接的输出保存到文件中。

telnet whois.internic.net 43

然后我

=google.com

并得到回应。

连接关闭后,我可以让它返回文件进行处理吗?

答案1

为什么不直接使用whois命令呢?

whois -h whois.internic.net =google.com > whois.txt

虽然在这种情况下我得到了更好的答案

whois =google.com > whois.txt

附录

Telnet 非常适合交互式探索任意基于文本的 TCP 协议(​​例如 SMTP、WHOIS 等),但它不太适合编写脚本

尝试netcat

$ echo =google.com | nc whois.internic.net 43 > whois.txt

$ head whois.txt

Whois Server Version 2.0

Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.

   Server Name: GOOGLE.COM.ZZZZZZZZZZZZZZZZZZZZZZZZZZZ.LOVE.AND.TOLERANCE.THE-WONDERBOLTS.COM
   IP Address: 50.62.130.9
   Registrar: GODADDY.COM, LLC



$ tail whois.txt
use electronic processes that are automated and high-volume to access or
query the Whois database except as reasonably necessary to register
domain names or modify existing registrations. VeriSign reserves the right
to restrict your access to the Whois database in its sole discretion to ensure
operational stability.  VeriSign may restrict or terminate your access to the
Whois database for failure to abide by these terms of use. VeriSign
reserves the right to modify these terms at any time.

The Registry database contains ONLY .COM, .NET, .EDU domains and
Registrars.



$ grep -i status whois.txt
   Status: clientDeleteProhibited
   Status: clientTransferProhibited
   Status: clientUpdateProhibited
   Status: serverDeleteProhibited
   Status: serverTransferProhibited
   Status: serverUpdateProhibited

我从 netcat 获得的输出与从脚本 + telnet 获得的输出相同。netcat 要容易得多

$ grep 'Name Server' whois.telnet | dos2unix | tee a
   Name Server: NS1.GOOGLE.COM
   Name Server: NS2.GOOGLE.COM
   Name Server: NS3.GOOGLE.COM
   Name Server: NS4.GOOGLE.COM
$  grep 'Name Server' whois.netcat | tee b
   Name Server: NS1.GOOGLE.COM
   Name Server: NS2.GOOGLE.COM
   Name Server: NS3.GOOGLE.COM
   Name Server: NS4.GOOGLE.COM
$ diff -s a b
Files a and b are identical

其他想法

编写 telnet 脚本的规范工具是expect

捕获终端输出的规范工具是script

在这种情况下,我认为这些不适合你的任务(但你可能不同意)

相关内容