Python Forum
telnetlib. configure hostnames
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
telnetlib. configure hostnames
#1
Hello everyone

I'm new in Python networking world. So I need you help. My goal is to configure different Hostnames for devices.

for example

Device_IP Hostname
192.168.1.1 TEST1
192.168.1.2 TEST2

I made excel document with IP address and Hostnames and wrote some script, but something is not work((
import telnetlib
import pandas as pd

df1 = pd.read_excel("nodes.xlsx",sheet_name='Sheet1')
df1list=df1.values.tolist()

for a in df1list:
    HOSTNAME=a[0]
    DEVICE_IP=a[1]

    try:
            HOST = DEVICE_IP
            user = "root"
            password = ""
            tn = telnetlib.Telnet(HOST,timeout=3)
            tn.read_until(b"Login: ")
            tn.write(user.encode('ascii') + b"\n")
            tn.read_until(b"Password: ")
            tn.write(password.encode('ascii') + b"\n")
            tn.write(b"/system identity user= + HOSTNAME \n")
            tn.write(b"exit \n")
            router_output = tn.read_all().decode('ascii')
            print(HOSTNAME+' '+DEVICE_IP,"Success")
            print(router_output)
            tn.close()
    except Exception as e:
        print(DEVICE_IP,"FAILED")
Can you help me to understand what is wrong?

Thank you


..
Reply
#2
tn.read_until(b"Login: ") - check this (b"username") , may this is username
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  telnetlib timeout kerzol81 0 3,356 Sep-12-2019, 08:38 AM
Last Post: kerzol81
  Telnetlib reading output petterg 1 11,199 Jul-06-2019, 12:08 PM
Last Post: searching1
  Python script hangs after entering username to remote login using telnetlib auto 0 4,780 Sep-10-2018, 01:10 PM
Last Post: auto
  telnetlib timeout expections handling issue anna 0 7,755 Jun-08-2018, 06:28 AM
Last Post: anna
  ip addresses to hostnames paulkt 1 2,672 Apr-16-2018, 07:22 PM
Last Post: wavic
  python telnetlib prompt matching issue anna 0 3,960 Jan-30-2018, 05:34 PM
Last Post: anna
  telnetlib.Telnet timeout issue.. taking much time anna 1 8,203 Jan-19-2018, 01:52 PM
Last Post: devs4p

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020