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.

Steve Bennett
  • 5,539
  • 12
  • 45
  • 57
  • 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 04: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 05:33
  • That doesn't make it on-topic, though. – EEAA Apr 17 '13 at 05:50
  • 5
    Hmm, looks like the scope of SF is much narrower than what's actually specified in the FAQ. (eg, http://meta.serverfault.com/questions/4111/what-is-a-professional-capacity ) – Steve Bennett Apr 17 '13 at 07: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 08:43
  • Well, there were a few things to test: was there actually a service listening as expected on the given port; was the server firewalled against that port; was there an intervening firewall between machine A and B (in this case, yes)... – Steve Bennett Apr 18 '13 at 00:01
  • `curl -v telnet://:` – slm Jan 27 '19 at 18:47

3 Answers3

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,710
  • 1
  • 18
  • 19
  • 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/

dmourati
  • 24,720
  • 2
  • 40
  • 69
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
  • 5,539
  • 12
  • 45
  • 57