- 19th Jul 2024
- 17:59 pm
In this assignment you need to make a script that is testing the credentials for a telnet connexion into the access point. It is to validate that the credentials (telnet ip/port and user/password) stored in the tb_test.json are correct. You have to use the module telnetlib. Our experts can assist you in creating a Python script that tests the credentials for a Telnet connection into the access point. We'll guide you on how to use the telnetlib
module to validate the credentials stored in the tb_test.json
file. Whether you need help with coding, debugging, or understanding the Telnet protocol, our team is here to support you every step of the way.
Script for Validating Telnet Connection Credentials - Get Assignment Solution
Explore a detailed assignment solution showcasing the Script for Validating Telnet Connection Credentials - Assignment Solution. Access the complete code, report, and screenshots for research and reference purposes. For more details:
Option 1: Download the complete solution on our Python Assignment Sample Solution page.
Option 2: Connect with our Python Tutors for online tutoring and clarifying doubts related to this assignment.
Option 3: Check out the partial solution in this blog post.
Free Assignment Solution - Script for Validating Telnet Connection Credentials
# -*- coding: utf-8 -*-
"""
Tests the credentials of a telnet connection given by telnet_ip
and telnet_port.
"""
import telnetlib
import json, sys
import time
TIMEOUT_OPEN = 3 # in seconds
TIMEOUT = 0.1
def tnc(tn, command, time_to_sleep=3, no_next=False):
tn.write(bytes(command, encoding='utf-8')) if no_next else tn.write(bytes(command + '\n', encoding='utf-8'))
time.sleep(time_to_sleep)
output = tn.read_very_eager().decode('ascii')
print(output)
return output
path = 'tb_test.json'
with open(path) as json_file:
db = json.load(json_file)
for ap in db['AP'].values():
print(ap['telnet_ip'])
print(ap['telnet_port'])
if ap['telnet_ip'] != '':
print(ap['user'])
print(ap['password'])
try:
tn = telnetlib.Telnet(ap['telnet_ip'],
port=ap['telnet_port'],
timeout=TIMEOUT_OPEN)
except:
print("Could not open telnet connection")
continue
output = tn.read_until(b"Username: ").decode("ascii")
if output.endswith("Username: "):
output1 = tnc(tn, ap['user'], 0.1)
output2 = tnc(tn, ap['password'], 0.1)
if "Invalid Login" in output2:
print("Wrong credentials!")
elif output2 == '':
print("Testing failed")
else:
print("Valid credentials")
tn.close()
# tn = telnetlib.Telnet(host=ap['telnet_ip'], port=ap['telnet_port'], timeout=30000)
# tn = telnetlib.Telnet(host="192.168.1.120", port="10001", timeout=30000)
# tn = telnetlib.Telnet(host="192.168.1.104", port="23", timeout=30000)
# tnc(tn, "show country")
Get the best Script for Validating Telnet Connection Credentials assignment help and tutoring services from our experts now!
About The Author - Aman Gupta
Aman Gupta is an experienced network engineer and software developer specializing in Python scripting for network automation and security. With extensive knowledge in using the telnetlib
module, Aman has successfully developed numerous scripts for validating Telnet connections and managing network devices. His proficiency in automating network tasks and troubleshooting connectivity issues makes him a valuable contributor to the field of network engineering.