Checking ports automatically can be stressful if there are quite a few addresses and ports to be checked.
And typing manually is prone to error by mistyping the IP Address and Port.
This is where automation comes into play.
Prepare the IP Address and Port on a text file, and once all is prepared.
Let Python do the job or the task to Telnet and check the port whether the system can successfully connect or not.
The tester just need to watch or monitor the terminal or do some other task, while waiting for the Python to do its job.
Simple code below shows, how to do this task.
#=====================================
import sys
import telnetlib
def get_all_ips(filename_to_check):
with open(filename_to_check, 'r') as entries:
for ip_entries in entries:
ip_and_port=ip_entries.split(" ")
the_ip=ip_and_port[0]
the_port_num=ip_and_port[1]
the_ip=the_ip.strip()
the_port_num=the_port_num.strip()
print("IP Address is: ",the_ip, "Port number is: ",the_port_num)
try:
conn = telnetlib.Telnet(the_ip,the_port_num)
telnet_response = the_ip +' ' + the_port_num +' - Able to reach - OK'
except:
telnet_response = the_ip +' ' + the_port_num +' - Failed cannot reach'
finally:
print(telnet_response)
if __name__ == "__main__":
get_all_ips("ip_and_ports.txt")
Cheers! Take care. Till next Time. Enjoy exploring the world of Python automation and enjoy the journey of learning..
Stay safe! and Keep things up!
Do ASAP, Always Say A Prayer...
Practice O.T.G. = Obedience To God
Make time for Prayer and Meditation.
================================
Free Android Apps:
Click links below to find out more:
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
https://play.google.com/store/apps/details?id=chrisjoms.myexcelapplicationguide
Heaven's Dew Fall Prayer app for Android :
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
Pray the Rosary every day, countless blessings will be showered upon your life if you recite the Rosary faithfully.
https://play.google.com/store/apps/details?id=com.myrosaryapp
Divine Mercy Chaplet Guide (A Powerful prayer) BFF = Be Filled Faith:
Comments
Post a Comment