0

we have to test on 100 servers whether telnet is installed or not? if installed we have to check port is working or not (telnet 10.20.30.40 1234) if not installed we have to install and test the port is enabled or not? is it possible in Python script, if yes please help.

Thanks in advance.

sreenid
  • 53
  • 1
  • 1
  • 4

1 Answers1

0

Try this:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('0.20.30.40',1234))
if result == 0:
   print "Port is open"
else:
   print "Port is not open"
sock.close()
Jayjay
  • 112
  • 1
  • 1
  • 9
  • thanks for the answer, it is working for to check the port is open or not. but is there a way in python to check telnet client is installed or not? (useually we use to install telnet client in windows start >> Server Manager >> Add roles and features .....etc >>features >> then select telnet client and install). we have CA software, that i am trying to automate. – sreenid Sep 16 '19 at 09:28