Ste*_*ett 25 networking telnet diagnostic
我正在尝试测试机器 A 是否可以在某些端口上连接到机器 B。机器 A 的系统管理员认为删除该telnet命令是合适的。什么是方便的替代品?机器 A 是 CentOS。
Gry*_*ius 29
iirc, telnet 不再默认安装在 centos 6 机器上。如果您没有类似telnet或nc可用的工具,您可以随时使用 python 与网络套接字通信。(不确定这是否符合您的“方便”要求……)
简单测试是否可以建立连接:
[gryphius@ut ~]$ python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> conn=socket.create_connection(('gmail-smtp-in.l.google.com',25))
Run Code Online (Sandbox Code Playgroud)
如果到目前为止没有抛出错误,则连接正常。如果您还想测试接收/发送数据,您可以继续这样:
>>> input=conn.makefile()
>>> print input.readline()
220 mx.google.com ESMTP p2si6911139eeg.7 - gsmtp
>>> conn.sendall('HELO example.com\r\n')
>>> print input.readline()
250 mx.google.com at your service
>>> conn.sendall('QUIT')
>>> conn.close()
>>>
Run Code Online (Sandbox Code Playgroud)
我想出了一个方法:
$ ssh -f -N machineA -L 10123:machineB:123
$ telnet localhost 10123
Run Code Online (Sandbox Code Playgroud)
它失败了,但我不确定这是否真的是诊断性的。经过进一步测试,它确实具有诊断意义。
| 归档时间: |
|
| 查看次数: |
84237 次 |
| 最近记录: |