Repository navigation
Expand file tree
/
Copy pathshow_vlans.py
More file actions
58 lines (47 loc) · 1.51 KB
/
Copy pathshow_vlans.py
File metadata and controls
58 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
__version__ = '0.9'
__author__ = 'Remi Batist'
# Overview of vlans including ip-addresses in procurve-style
# Example below
# VLAN-ID | IP Address IP Subnet NAME
# ------- | --------------- --------------- ---------------
# 1 | VLAN 0001
# 6 | VLAN 0006
# 10 | 10.10.10.2 255.255.255.0 VLAN10-SERVERS
# 20 | wifi
# 30 | 10.10.30.253 255.255.255.0 VLAN30-CLIENTS
#### Importing python modules
import comware
def main():
print 'VLAN-ID' + '\t' + '| IP Address' + '\t' + ' IP Subnet' + '\t ' + ' NAME'
print '------- | --------------- --------------- ---------------'
#### Importing current information
result = comware.CLI('display vlan all', False).get_output()
vlanid = ''
vlanna = ''
vlanip = ''
vlansn = ''
found = False
#### Collecting specific items
for line in result:
if 'VLAN ID' in line:
s1 = line.rindex(':') + 1
e1 = len(line)
vlanid = line[s1:e1]
vlanip = ' '
vlansn = ' '
elif 'IPv4 address' in line:
s2 = line.rindex(':') + 2
e2 = len(line)
vlanip = line[s2:e2]
elif 'IPv4 subnet mask' in line:
s5 = line.rindex(':') + 2
e5 = len(line)
vlansn = line[s5:e5]
elif 'Name' in line:
s3 = line.rindex(':') + 2
e3 = len(line)
vlanna = line[s3:e3]
#### Printing specific items
print "%-7s | %-16s %-16s %s" % (vlanid, vlanip, vlansn, vlanna)
if __name__ == "__main__":
main()