I'm trying to test whether machine A can connect to machine B on certain ports. The sysadmins of machine A have seen fit to remove the telnet command. What would be a convenient replacement? Machine A is CentOS.
Asked
Active
Viewed 9.1k times
25
Steve Bennett
- 6,000
3 Answers
29
iirc, telnet isn't installed by default on centos 6 machines anymore. if you don't have tools like telnet or nc available you can always talk to a network socket using python. (not sure if this fits your "convenient" requirement though... )
to simply test if the connection can be established:
[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))
If that didn't throw an error so far the connection is ok. If you also want to test receiving/sending data, you could continue like this:
>>> 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()
>>>
Gryphius
- 2,760
- 1
- 20
- 21
8
Any of: nc (netcat), nmap, hping.
http://linux.byexamples.com/archives/258/when-netcat-act-as-telnet-client-it-becomes-better/
dmourati
- 26,498
5
A method I came up with:
$ ssh -f -N machineA -L 10123:machineB:123
$ telnet localhost 10123
It failed, but I wasn't sure whether that was actually diagnostic or not. Having tested further, it is indeed diagnostic.
Steve Bennett
- 6,000