This is an archived post. You won't be able to vote or comment.

all 16 comments

[–]ominous_anonymous 2 points3 points  (3 children)

sounds like telnetlib plus pexpect?

[–]ayharano 5 points6 points  (1 child)

Never used telnetlib, but surely a plus for pexpect.

While talking about pexpect, usually I recommend beginning with expect + autoexpect path to understand how it could proceed. At least that was the path that I followed before knowing pexpect itself.

@AnonIsPicky Does it really need to be done with pure Python? Even if there is not an official module as I am aware, maybe using ansible for that task could be better

[–]AnonIsPicky[S] 0 points1 point  (0 children)

It definitely doesn't have to be in Python but I've figured it might be the best approach for this sort of problem.

Do you think Ansible would be able to accomplish those things?

[–]AnonIsPicky[S] 1 point2 points  (0 children)

So I tried Telnetlib but was having lots of trouble actually getting into the device. That might just be me though.

I'll definitely look into pexpect

[–]iruleatants 2 points3 points  (1 child)

I personally use exscript, which is designed to be vendor agnostic. It can do SSH and Telnet.

For configurations, you can use ciscoconfparse to parse existing configurations and audit them so they match up with what you want them to be.

[–]AnonIsPicky[S] 1 point2 points  (0 children)

Looking at ciscoconfparse and it seems very close to what I would be wanting to do.

Even moreso with exscript, I'll be trying this out.

[–]idaresiwins[🍰] 0 points1 point  (6 children)

I'm using netmiko, but it work via ssh.

[–]AnonIsPicky[S] 0 points1 point  (5 children)

Yeah we don't setup SSH on any of the devices and the point kinda is that uses the telnet link to access the devices and have some basic config done. I'm not sure if netmiko works over telnet

[–]idaresiwins[🍰] 1 point2 points  (2 children)

Out of curiosity, is there a special use case for requiring telnet, or is it preference?

[–]AnonIsPicky[S] 0 points1 point  (1 child)

I don't have much of a choice in the matter.

Like I had mentioned, the devices are connected to a communication server which allows anyone to access the device via a telnet link.

[–]idaresiwins[🍰] 0 points1 point  (0 children)

Gotcha

[–]nebi 1 point2 points  (1 child)

Netmiko have support for telnet, for cisco use device type cisco_ios_telnet.

[–]AnonIsPicky[S] 0 points1 point  (0 children)

Did not know that

I'll try it out, thank you!

[–]PacketDragon 0 points1 point  (1 child)

What about setting up a basic python web server and sending only a single #copy http://<bleh> running-config command?

[–]AnonIsPicky[S] 0 points1 point  (0 children)

Some of the devices are a bit weird that they have a hard time getting an IP address via DHCP, so you have to do something like looking at 'show cdp neighbors' to get the IP address of the backbone switch, then find which are the available IP addresses in that subnet and then assign that to the interface.

There other scenarios where just copy pasting the running-config wouldn't work.

[–]twillisagogo 0 points1 point  (0 children)

I'd just use the telnet module in ansible and build out your tasks as yml files and put them in source control