Jan-10-2018, 08:26 AM
telnet output is as below, want to print vlan (vid) and mac, please suggest changes
Port: 1
index vid mac
----- ---- -----------------
1 3738 e4:6f:13:80:dd:52
Port: 3
index vid mac
----- ---- -----------------
2 3738 c4:6e:1f:2f:ac:a6
Port: 5
index vid mac
----- ---- -----------------
3 3738 e4:6f:13:81:fc:a2
Port: 13
index vid mac
----- ---- -----------------
4 3738 48:ee:0c:d1:ba:95
Port: 14
index vid mac
----- ---- -----------------
5 3738 e8:37:7a:9d:0e:66
Port: 15
index vid mac
----- ---- -----------------
6 3738 00:17:7c:6d:64:b4
Port: 20
index vid mac
----- ---- -----------------
7 3638 6c:72:20:54:69:74
Port: 21
index vid mac
----- ---- -----------------
8 3638 10:7b:ef:a6:4b:dc
Port: 25
index vid mac
----- ---- -----------------
9 3638 00:17:7c:80:7a:43
Port: 1
index vid mac
----- ---- -----------------
1 3738 e4:6f:13:80:dd:52
Port: 3
index vid mac
----- ---- -----------------
2 3738 c4:6e:1f:2f:ac:a6
Port: 5
index vid mac
----- ---- -----------------
3 3738 e4:6f:13:81:fc:a2
Port: 13
index vid mac
----- ---- -----------------
4 3738 48:ee:0c:d1:ba:95
Port: 14
index vid mac
----- ---- -----------------
5 3738 e8:37:7a:9d:0e:66
Port: 15
index vid mac
----- ---- -----------------
6 3738 00:17:7c:6d:64:b4
Port: 20
index vid mac
----- ---- -----------------
7 3638 6c:72:20:54:69:74
Port: 21
index vid mac
----- ---- -----------------
8 3638 10:7b:ef:a6:4b:dc
Port: 25
index vid mac
----- ---- -----------------
9 3638 00:17:7c:80:7a:43
#!/usr/bin/python import paramiko import sys import os import xlrd import unidecode import telnetlib import time import re from time import sleep mac = re.compile(r'[a-fA-F0-9]{2}[:][a-fA-AF0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}[:][a-fA-F0-9]{2}') vlan = re.compile(r'\d{4}') user = 'admin' password = '1234' with open('zyxel.txt','r') as ipfile: for sr_no, line in enumerate(ipfile, start=1): host = line.strip() try: print 'Connecting .....'+str(host) telnet = telnetlib.Telnet(host, 23, 2) telnet.read_until('User name:', 3) telnet.write(user.encode('ascii') + '\r') telnet.read_until('Password:', 3) telnet.write(password.encode('ascii') + '\r') #telnet.read_until('>') telnet.write('statistics mac 1~48' + '\r') telnet.read_until('>') telnet.write(' exit''\r') output = telnet.read_all() print 'printing output.....' for line in output: if vlan in line: vlan = DslamVlan if mac in line: mac = DslamPortMac print DslamVlan+' '+DslamPortMac except Exception as excp: print(excp)