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!

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

mac.write(line)

instead of:

mac.write(line+"\n")

It was overwriting each line.