25

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.

7
  • 2
    Talk with the sysadmins of A and inform them of your need. As far as alternatives go, look into netcat. This is off-topic as you don't have the privileges on the machine in question to fix the problem. – EEAA Apr 17 '13 at 4:47
  • "Talk with the sysadmins of A and inform them of your need." - unlikely in this environment. \ Netcat isn't installed. \ I guess - I am sysadmin on machine B though. – Steve Bennett Apr 17 '13 at 5:33
  • That doesn't make it on-topic, though. – EEAA Apr 17 '13 at 5:50
  • 5
    Hmm, looks like the scope of SF is much narrower than what's actually specified in the FAQ. (eg, meta.serverfault.com/questions/4111/… ) – Steve Bennett Apr 17 '13 at 7:16
  • If you're the sysadmin of machine B, all you can do is make sure that machine B is allowing access. It's the job of the sysadmins of machine A to either give you the tools you need, or to do the testing themselves. As it stands now, since you don't have any program that can be used to initiate the connection, the answer is that no, A cannot connect. – Jenny D Apr 17 '13 at 8:43
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()
>>> 
1
  • 1
    Indeed it isn't convenient, but it got the job done when nothing else was available. (I needed to validate that gpsd was publishing to localhost:2497 on an embedded system: success!) – Robert Calhoun Jan 21 '16 at 16:21
8

Any of: nc (netcat), nmap, hping.

http://linux.byexamples.com/archives/258/when-netcat-act-as-telnet-client-it-becomes-better/

http://nmap.org/

http://www.hping.org/

1
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.