Mar-19-2018, 07:08 AM
Below script read line from ARP file and split line into multiple list, like IP, MAC, interface and numeric interface,
arp file details are as below
IP = 10.10.1.2, mac = 001a.e36f.07c1, interface = GigabitEthernet1/0/2.165, numeric_interface = 1/0/2.165
matching numeric_interface and printing svlan and cvlan in line.
sample conf is
interface gigabitEthernet 3/0/6.9332109
svlan id 933 2109
ip description fup16-16384_4-0220365059
ip unnumbered loopback 123252130
no ip proxy-arp
no ip redirects
!
interface gigabitEthernet 3/0/6.9332537
svlan id 933 2537
ip description res16-2048-0221468429
ip unnumbered loopback 240
no ip proxy-arp
no ip redirects
!
interface gigabitEthernet 3/0/6.9332573
!
interface gigabitEthernet 3/0/6.9332654
svlan id 933 2654
ip description fup16-10240-0221460185
ip unnumbered loopback 229
no ip proxy-arp
no ip redirects
=-=-=-=-=-=-=-=-=-
svlan id 933 2654
in below above line:- 993 is svlan and 2654 cvlan
arp file details are as below
Quote:10.10.1.2 21050 0030.6e4a.362a GigabitEthernet1/0/2.1820150
10.10.1.3 21590 f01f.aff1.a65e GigabitEthernet1/0/2.1820150
10.11.1.1 4640 0019.560b.9241 GigabitEthernet1/0/2.115
10.11.1.2 21340 0017.e029.2c41 GigabitEthernet1/0/2.125
10.11.1.3 7980 001a.a226.70c1 GigabitEthernet1/0/2.135
10.11.1.4 16410 001a.e36f.f6c1 GigabitEthernet1/0/2.145
10.11.1.5 6730 001a.a226.8fc1 GigabitEthernet1/0/2.155
10.11.1.6 8240 001a.e36f.07c1 GigabitEthernet1/0/2.165
IP = 10.10.1.2, mac = 001a.e36f.07c1, interface = GigabitEthernet1/0/2.165, numeric_interface = 1/0/2.165
matching numeric_interface and printing svlan and cvlan in line.
sample conf is
interface gigabitEthernet 3/0/6.9332109
svlan id 933 2109
ip description fup16-16384_4-0220365059
ip unnumbered loopback 123252130
no ip proxy-arp
no ip redirects
!
interface gigabitEthernet 3/0/6.9332537
svlan id 933 2537
ip description res16-2048-0221468429
ip unnumbered loopback 240
no ip proxy-arp
no ip redirects
!
interface gigabitEthernet 3/0/6.9332573
!
interface gigabitEthernet 3/0/6.9332654
svlan id 933 2654
ip description fup16-10240-0221460185
ip unnumbered loopback 229
no ip proxy-arp
no ip redirects
=-=-=-=-=-=-=-=-=-
svlan id 933 2654
in below above line:- 993 is svlan and 2654 cvlan
import re
#lists to store details
ip = []
mac = []
interface = []
numric_interface =[]
#with open('E320conf.txt','r') as conffile:
# content = conffile.readlines()
with open('E320arp.txt','r') as arpfile:
for line in arpfile:
#arp_line = line.strip()
arp = re.sub('\s{2,}',' ',line).split(' ')
# above line to remove multiple spaces and replace with single space
ip.append(arp[1])
#append ip address in list
mac.append(arp[3])
#append mac address in list
interface.append(arp[4])
#append interface in list
numric_interface.append(arp[4][15:])
#slice and append Numric interface
with open('E320conf.txt','r') as conf_file:
content = conf_file.readlines()
data = iter(content)
for conf_file_line in data:
for x in numric_interface,ip, mac:
if 'svlan' in conf_file_line:
svlan = conf_file_line.split(' ')[3]
cvlan = conf_file_line.split(' ')[4]
print('{} {} {} {} {}'.format(ip[1],mac[1],numric_interface[1],svlan,cvlan))Output:10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
949 2503
10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
971 3025
10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
971 3025
10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
971 3025
10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
971 3025
10.10.1.3 f01f.aff1.a65e 1/0/2.1820150
971 3025how to iterate list and print on same line
