0

All,

I have the following that I'm trying to write:

mac = open("maclisting.txt","a")
tn = telnetlib.Telnet(HOST)
tn.read_until(b"Username: ")
tn.write(b"xxxx\n")
tn.read_until(b"Password: ")
tn.write(b"xxxx\n")
tn.read_until(b"#", 5)
tn.write(b"term leng 0\n")
tn.read_until(b"#", 5)
tn.write(b"sh arp\n")
tn.write(b"exit\n")
results = (tn.read_all().decode('ascii').split("\n"))
for line in results:
	if len(line) > 40:
		print(line,)
		mac.write(line,)
	else:
		continue

The above "works", but the problem that I'm having is after the len(line) code. It prints all of the arp entries, but mac.write(line,) only writes the last result.

My next question about telnetlib is: Is there a way of running multiple commands and get those results without having to close the connection everytime? For example, if I want to run "sh arp" and "sh mac address", can I do that in a single connection and still write the results?

Thanks!

1
Contributor
1
Reply
3
Views
6 Years
Discussion Span
Last Post by nutrion
0

I figured out why it was doing it. I had:

mac.write(line)

instead of:

mac.write(line+"\n")

It was overwriting each line.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.