import os
import re
import pexpect
os.system("rm 112.txt")
thefile=open("112.txt", "w+")
child=pexpect.spawn("ssh adm@192.168.0.112")
child.expect("password:")
child.sendline("123")
child.expect("continue")
child.sendline("\r")
child.expect("SZ")
child.sendline("show int status")
child.expect("Enter")
result1=child.before.decode()
child.sendline(" ")
child.expect("SZ")
result2=child.before.decode()
thefile.write(result1)
thefile.write(result2)
thefile.close()
thefile=open("112.txt")
lines=thefile.readlines()
port_status=[]
for member in lines:
pattern=" \d{1,2}"
source=member
result=re.search(pattern, source)
if(result):
result=result.group()
result=result.lstrip(" ")
port_status.append(result)
pattern="Up|Down"
result=re.search(pattern, source)
result=result.group()
port_status.append(result)
thefile.close()