-
Notifications
You must be signed in to change notification settings - Fork 1
/
RcvdRouteAudit.py
1121 lines (1040 loc) · 42.6 KB
/
RcvdRouteAudit.py
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
'''
Router Audit
Author Siggi Bjarnason Copyright 2017
Website http://www.ipcalc.us/ and http://www.icecomputing.com
Description:
This is script that will discover all the BGP peers on a particular Cisco Router running
and caputer all the routes being received over each peer.
Following packages need to be installed as administrator
pip install pypiwin32
pip install paramiko
pip install playsound
'''
strSummarySheet = "BGP Summary"
strDetailSheet = "By Router"
strPrefixeSheet = "By Prefix"
iMaxError = 6 # How many times can we experience an error on a single device before marking the device failed and moving on, 0 based
iMaxAuthFail = 2 # How many auth failures can happen in a row. Zero based.
dictBaseCmd = {
"IOS-XR":{
"Match":"IOS XR",
"IPv4-GT-Summary":"show bgp ipv4 unicast summary",
"IPv4-VRF-Summary":"show bgp vrf {} ipv4 unicast summary",
"IPv4-GT-Receive":"show bgp ipv4 unicast neighbors {} routes",
"IPv4-VRF-Receive":"show bgp vrf {} ipv4 unicast neighbors {} routes",
"IPv4-GT-Description":"show bgp ipv4 unicast neighbors {} | include Description:",
"IPv4-VRF-Description":"show bgp vrf {} ipv4 unicast neighbors {} | include Description:",
"IPv6-GT-Summary":"show bgp ipv6 unicast summary",
"IPv6-VRF-Summary":"show bgp vrf {} ipv6 unicast summary",
"IPv6-GT-Receive":"show bgp ipv6 unicast neighbors {} routes",
"IPv6-VRF-Receive":"show bgp vrf {} ipv6 unicast neighbors {} routes",
"IPv6-GT-Description":"show bgp ipv6 unicast neighbors {} | include Description:",
"IPv6-VRF-Description":"show bgp vrf {} ipv6 unicast neighbors {} | include Description:",
"shVRF":"show vrf all"
},
"IOS-XE":{
"Match":"IOS XE",
"IPv4-GT-Summary":"show bgp ipv4 unicast summary",
"IPv4-VRF-Summary":"show bgp vrf {} vpnv4 unicast summary",
"IPv4-GT-Receive":"show bgp ipv4 unicast neighbors {} routes",
"IPv4-VRF-Receive":"show bgp vrf {} vpnv4 unicast neighbors {} routes",
"IPv4-GT-Description":"show bgp ipv4 unicast neighbors {} | include Description:",
"IPv4-VRF-Description":"show bgp vrf {} vpnv4 unicast neighbors {} | include Description:",
"IPv6-GT-Summary":"show bgp ipv6 unicast summary",
"IPv6-VRF-Summary":"show bgp vrf {} vpnv6 unicast summary",
"IPv6-GT-Receive":"show bgp ipv6 unicast neighbors {} routes",
"IPv6-VRF-Receive":"show bgp vrf {} vpnv4 unicast neighbors {} routes",
"IPv6-GT-Description":"show bgp ipv6 unicast neighbors {} | include Description:",
"IPv6-VRF-Description":"show bgp vrf {} vpnv4 unicast neighbors {} | include Description:",
"shVRF":"show vrf brief"
},
"Nexus":{
"Match":"NX-OS",
"IPv4-GT-Summary":"show ip bgp summary",
"IPv4-VRF-Summary":"show ip bgp vrf {} summary",
"IPv4-GT-Receive":"show ip bgp neighbors {} routes",
"IPv4-VRF-Receive":"show ip bgp vrf {} neighbors {} routes",
"IPv4-GT-Description":"show ip bgp neighbors {} | include Description:",
"IPv4-VRF-Description":"show ip bgp vrf {} neighbors {} | include Description:",
"IPv6-GT-Summary":"show ipv6 bgp summary",
"IPv6-VRF-Summary":"show ipv6 bgp vrf {} summary",
"IPv6-GT-Receive":"show ipv6 bgp neighbors {} routes",
"IPv6-VRF-Receive":"show ipv6 bgp vrf CORESEC neighbors {} routes ",
"IPv6-GT-Description":"show ipv6 bgp neighbors {} | include Description:",
"IPv6-VRF-Description":"show ipv6 bgp vrf CORESEC neighbors {} | include Description:",
"shVRF":"show vrf all"
},
"IOS":{
"Match":" IOS ",
"IPv4-GT-Summary":"show ip bgp summary",
"IPv4-VRF-Summary":"show ip bgp vpnv4 vrf {} summary",
"IPv4-GT-Receive":"show ip bgp neighbors {} routes",
"IPv4-VRF-Receive":"show ip bgp vpnv4 vrf {} neighbors {} routes",
"IPv4-GT-Description":"show ip bgp neighbors {} | include Description:",
"IPv4-VRF-Description":"show ip bgp vpnv4 vrf {} neighbors {} | include Description:",
"IPv6-GT-Summary":"show bgp ipv6 unicast summary",
"IPv6-VRF-Summary":"show ip bgp vpnv6 unicast vrf {} summary",
"IPv6-GT-Receive":"show ip bgp ipv6 unicast neighbors {} routes",
"IPv6-VRF-Receive":"show ip bgp vpnv6 unicast vrf {} neighbors {} routes",
"IPv6-GT-Description":"show ip bgp ipv6 unicast neighbors {} | include Description:",
"IPv6-VRF-Description":"show ip bgp vpnv6 unicast vrf {} neighbors {} | include Description:",
"shVRF":"show vrf brief"
}
}
def ResultHeaders():
try:
wsResult.Cells(1,1).Value = "Router"
wsResult.Cells(1,2).Value = "Version"
wsResult.Cells(1,3).Value = "Neighbor"
wsResult.Cells(1,4).Value = "Remote AS"
wsResult.Cells(1,5).Value = "VRF"
wsResult.Cells(1,6).Value = "Recv count"
wsResult.Cells(1,7).Value = "Adv count"
wsResult.Cells(1,8).Value = "Description"
wsDetails.Cells(1,1).Value = "Router"
wsDetails.Cells(1,2).Value = "Neighbor"
wsDetails.Cells(1,3).Value = "VRF"
wsDetails.Cells(1,4).Value = "Adv Prefix"
wsDetails.Cells(1,5).Value = "Description"
wsPrefixes.Cells(1,1).Value = "Prefix"
wsPrefixes.Cells(1,2).Value = "VRFs"
wsPrefixes.Cells(1,3).Value = "Peer Count"
wsPrefixes.Cells(1,4).Value = "Router-VRF-PeerIP"
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
def CollectVRFs():
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["shVRF"])
strOutputList = strOut.splitlines()
bInSection = False
lstVRFs = []
LogEntry ("There are {} lines in the show vrf output".format(len(strOutputList)))
for strLine in strOutputList:
if "Exception:" in strLine:
wsResult.Cells(iOutLineNum,3).Value = strLine
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
break
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
strLineTokens = strLine.split()
if len(strLineTokens) > 1:
if strHostVer == "IOS-XR":
if bInSection and strLineTokens[0] != "import" and strLineTokens[0] != "export" and "not set" not in strLine:
lstVRFs.append(strLineTokens[0])
if strLineTokens[0]== "VRF" and strLineTokens[1]== "RD" and strLineTokens[2]== "RT":
bInSection = True
if strHostVer == "IOS-XE":
if bInSection and "not set" not in strLine:
lstVRFs.append(strLineTokens[0])
if strLineTokens[0]== "Name" and strLineTokens[1]== "Default" and strLineTokens[2]== "RD":
bInSection = True
if strHostVer == "Nexus":
if bInSection and strLineTokens[0] != "default" and strLineTokens[0] != "management" :
lstVRFs.append(strLineTokens[0])
if strLineTokens[0]== "VRF-Name" and strLineTokens[1]== "VRF-ID" and strLineTokens[2]== "State":
bInSection = True
if strHostVer == "IOS":
if bInSection and len(strLineTokens) > 2 :
lstVRFs.append(strLineTokens[0])
if strLineTokens[0]== "Name" and strLineTokens[1]== "Default" and strLineTokens[2]== "RD":
bInSection = True
LogEntry ("VRF's Collected: {}".format(lstVRFs))
return lstVRFs
def AnalyzeIPv4Results(strOutputList, strVRF):
global iOutLineNum
dictIPv4Peers = {}
bNeighborSection = False
LogEntry ("There are {} lines in the show bgp IPv4 summary output".format(len(strOutputList)))
for strLine in strOutputList:
if "Exception:" in strLine:
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,3).Value = strLine
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
break
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
strLineTokens = strLine.split()
if strHostVer == "IOS-XR" or strHostVer == "IOS-XE" or strHostVer == "IOS" or strHostVer == "Nexus":
# LogEntry("Finding local AS")
if "local AS number " in strLine:
iLoc = strLine.find("number ")+7
iLocalAS = strLine[iLoc:]
LogEntry ("Local AS:{}".format(iLocalAS))
if len(strLineTokens) > 1:
if bNeighborSection:
if len(strLineTokens) > 8:
iRemoteAS = strLineTokens[2]
strCount = str(strLineTokens[9])
strPeerIP = strLineTokens[0]
if iRemoteAS != iLocalAS and strCount != "Idle" and strCount != "Active" :
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,1).Value = strHostname
wsResult.Cells(iOutLineNum,2).Value = strHostVer
wsResult.Cells(iOutLineNum,3).Value = strPeerIP
wsResult.Cells(iOutLineNum,4).Value = strLineTokens[2]
wsResult.Cells(iOutLineNum,5).Value = strVRF
wsResult.Cells(iOutLineNum,6).Value = strLineTokens[9]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
dictIPv4Peers[strPeerIP] = {"VRF":strVRF,"LineID":iOutLineNum}
else:
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,2).Value = "Line {} was unexpectedly short".format(strLine)
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
if strLineTokens[0]== "Neighbor":
bNeighborSection = True
else:
bNeighborSection = False
return dictIPv4Peers
# end function AnalyzeIPv4Results
def AnalyzeIPv6Results(strOutputList, strVRF):
global iOutLineNum
dictPeers = {}
bNeighborSection = False
strPeerIP = ""
LogEntry ("There are {} lines in the show bgp IPv6 summary output".format(len(strOutputList)))
for strLine in strOutputList:
if "Exception:" in strLine:
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,3).Value = strLine
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
break
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
strLineTokens = strLine.split()
if strHostVer == "IOS-XR" or strHostVer == "IOS-XE" or strHostVer == "IOS" or strHostVer == "Nexus":
if "local AS number " in strLine:
iLoc = strLine.find("number ")+7
iLocalAS = strLine[iLoc:]
if len(strLineTokens) > 0:
if bNeighborSection:
if strLineTokens[0].find(":") == 4:
strPeerIP = strLineTokens[0]
bLine2 = False
else:
bLine2 = True
if len(strLineTokens) > 8:
if bLine2:
iRemoteAS = strLineTokens[1]
strCount = str(strLineTokens[8])
else:
iRemoteAS = strLineTokens[2]
strCount = str(strLineTokens[9])
if iRemoteAS != iLocalAS and strCount != "Idle" and strCount != "Active" and strPeerIP != "":
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,1).Value = strHostname
wsResult.Cells(iOutLineNum,2).Value = strHostVer
wsResult.Cells(iOutLineNum,3).Value = strPeerIP
wsResult.Cells(iOutLineNum,4).Value = iRemoteAS
wsResult.Cells(iOutLineNum,5).Value = strVRF
wsResult.Cells(iOutLineNum,6).Value = strCount
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
dictPeers[strPeerIP] = {"VRF":strVRF,"LineID":iOutLineNum}
if strLineTokens[0]== "Neighbor":
bNeighborSection = True
else:
bNeighborSection = False
return dictPeers
# end function AnalyzeIPv6Results
def AnalyzeIPv4Routes(strOutList,strVRF,strPeerIP,strHostname,strDescr,iLineNum):
global iOut2Line
global dictPrefixes
bInSection = False
iStartLine = iOut2Line
LogEntry ("Analyzing received IPv4 routes. There are {} lines in the output".format(len(strOutList)))
if len(strOutList) > 0:
if "Exception:" in strOutList[0]:
iOut2Line += 1
wsResult.Cells(iOut2Line,3).Value = strOutList[0]
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
return
for strLine in strOutList:
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
iCurLine = iOut2Line - iStartLine + 1
if iCurLine%500 == 0:
print ("Completed {:.1%}".format(iCurLine/len(strOutList)))
if strHostVer == "IOS-XR":
strLineTokens = strLine.split()
if len(strLineTokens) > 1:
if bInSection and strLineTokens[0] != "Route" and strLineTokens[0] != "Processed":
strRcvdPrefix = strLineTokens[1]
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}
if strLineTokens[0] == "Network":
bInSection = True
if strLineTokens[0] == "Processed":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[1]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
if strHostVer == "IOS-XE" or strHostVer == "IOS":
strLineTokens = strLine.split()
if len(strLineTokens) > 1:
if bInSection and strLineTokens[0] != "Total" and strLineTokens[0] != "Network" and strLineTokens[1].count(".") == 3 :
strRcvdPrefix = strLineTokens[1]
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}
if strLineTokens[0] == "Network":
bInSection = True
if strLineTokens[0] == "Total":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[4]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
if strHostVer == "Nexus":
strLineTokens = strLine[3:].split()
if len(strLineTokens) > 1:
if bInSection and strLineTokens[0] != "Total" and strLineTokens[0] != "Network" and strLineTokens[0].count(".") == 3 :
strRcvdPrefix = strLineTokens[0]
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}
if strLineTokens[0] == "Network":
bInSection = True
if strLineTokens[0] == "Total":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[4]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
print ("Completed {:.1%}".format(1))
# end function AnalyzeIPv4Routes
def AnalyzeIPv6Routes(strOutList,strVRF,strPeerIP,strHostname,strDescr,iLineNum):
global iOut2Line
global dictPrefixes
iPrefixCount = 0
strNextHop = ""
iStartLine = iOut2Line
LogEntry ("Analyzing received IPv6 routes. There are {} lines in the output".format(len(strOutList)))
if len(strOutList) > 0:
if "Exception:" in strOutList[0]:
iOut2Line += 1
wsResult.Cells(iOut2Line,3).Value = strOutList[0]
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
return
for strLine in strOutList:
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
iCurLine = iOut2Line - iStartLine + 1
if iCurLine%500 == 0:
print ("Completed {:.1%}".format(iCurLine/len(strOutList)))
if strHostVer == "IOS-XR":
strLineTokens = strLine.split()
if len(strLineTokens) > 0:
if strLineTokens[0].find(":") == 4 and "/" in strLineTokens[0] :
if iPrefixCount == 0:
if len(strLineTokens) > 1:
strNextHop = strLineTokens[1]
strRcvdPrefix = strLineTokens[0]
iPrefixCount += 1
if iPrefixCount == 1 and strNextHop == "":
strNextHop = strLineTokens[0]
if strNextHop != "" and strNextHop != strLineTokens[0]:
strRcvdPrefix = strLineTokens[0]
iPrefixCount += 1
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}
if strLineTokens[0] == "Processed":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[1]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
if strHostVer == "IOS-XE" or strHostVer == "IOS":
strLineTokens = strLine.split()
if len(strLineTokens) > 1:
if strLineTokens[1].find(":") == 4:
if iPrefixCount == 0:
if len(strLineTokens) > 1:
strNextHop = strLineTokens[1]
strRcvdPrefix = strLineTokens[1]
iPrefixCount += 1
if iPrefixCount == 1 and strNextHop == "":
strNextHop = strLineTokens[1]
if strNextHop != "" and strNextHop != strLineTokens[1]:
strRcvdPrefix = strLineTokens[1]
iPrefixCount += 1
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}# end function AnalyzeIPv6Routes
if strLineTokens[0] == "Total":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[4]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
if strHostVer == "Nexus":
strLineTokens = strLine[3:].split()
if len(strLineTokens) > 0:
if (strLineTokens[0].find(":") == 4 and "/" in strLineTokens[0]) or strLineTokens[0]=="0::/0" :
if iPrefixCount == 0:
if len(strLineTokens) > 1:
strNextHop = strLineTokens[1]
strRcvdPrefix = strLineTokens[0]
iPrefixCount += 1
if iPrefixCount == 1 and strNextHop == "":
strNextHop = strLineTokens[0]
if strNextHop != "" and strNextHop != strLineTokens[0]:
strRcvdPrefix = strLineTokens[0]
iPrefixCount += 1
try:
iOut2Line += 1
wsDetails.Cells(iOut2Line,1).Value = strHostname
wsDetails.Cells(iOut2Line,2).Value = strPeerIP
wsDetails.Cells(iOut2Line,3).Value = strVRF
wsDetails.Cells(iOut2Line,4).Value = strRcvdPrefix
wsDetails.Cells(iOut2Line,5).Value = strDescr
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strRouterVRFPeer = strHostname + "-" + strVRF + "-" + strPeerIP
if strRcvdPrefix in dictPrefixes:
dictPrefixes[strRcvdPrefix]["Peer"].append(strRouterVRFPeer)
if strVRF not in dictPrefixes[strRcvdPrefix]["VRF"]:
dictPrefixes[strRcvdPrefix]["VRF"].append(strVRF)
else:
dictPrefixes[strRcvdPrefix]={"VRF":[strVRF],"Peer":[strRouterVRFPeer]}
if strLineTokens[0] == "Processed":
try:
wsResult.Cells(iLineNum,7).Value = strLineTokens[1]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
print ("Completed {:.1%}".format(1))
def ParseDescr(strOutList,iLineNum):
LogEntry ("Grabbing peer description. There are {} lines in the output".format(len(strOutList)))
for strLine in strOutList:
if "Exception:" in strLine:
wsResult.Cells(iLineNum,7).Value = strLine
bFoundABFACL = True
LogEntry ("Found an exception message, aborting analysis")
break
if len(strLine) > 0:
if strLine[0] == "%":
LogEntry ("Error: {}".format(strLine))
break
if strHostVer == "IOS-XR" or strHostVer == "IOS-XE" or strHostVer == "IOS" or strHostVer == "Nexus":
if "Description" in strLine:
# print ("Descr line: {}".format(strLine))
try:
wsResult.Cells(iLineNum,8).Value = strLine[14:]
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
return strLine[14:]
#end function ParseDescr
import tkinter as tk
from tkinter import filedialog, messagebox
from playsound import playsound, PlaysoundException
import win32com.client as win32 #pip install pypiwin32
import getpass
import time
import sys
import paramiko #pip install paramiko
import socket
import os
xlSrcExternal = 0 #External data source
xlSrcModel = 4 #PowerPivot Model
xlSrcQuery = 3 #Query
xlSrcRange = 1 #Range
xlSrcXml = 2 #XML
xlGuess = 0 # Excel determines whether there is a header, and where it is, if there is one.
xlNo = 2 # Default. The entire range should be sorted.
xlYes = 1 # The entire range should not be sorted.
dictSheets={}
dictDevices={}
dictPrefixes={}
lstVRFs=[]
lstRequiredElements=["Match","IPv4-GT-Summary","IPv4-VRF-Summary","IPv4-GT-Receive","IPv4-VRF-Receive","IPv4-GT-Description","IPv4-VRF-Description",
"shVRF","IPv6-GT-Summary","IPv6-VRF-Summary","IPv6-GT-Receive","IPv6-VRF-Receive","IPv6-GT-Description","IPv6-VRF-Description"]
iResultNum = 0
iResult2Num = 0
iResult3Num = 0
iResultColNum = 1
iDetailsColNum = 1
iPrefixColNum = 1
tStart=time.time()
iInputColumn = 1
strOutFolderName = strSummarySheet
def getInput(strPrompt):
if sys.version_info[0] > 2 :
return input(strPrompt)
else:
return raw_input(strPrompt)
# end getInput
def GetResults(strHostname,strCmd):
try:
SSH = paramiko.SSHClient()
SSH.set_missing_host_key_policy(paramiko.AutoAddPolicy())
SSH.connect(strHostname, username=strUserName, password=strPWD, look_for_keys=False, allow_agent=False)
stdin, stdout, stderr = SSH.exec_command(strCmd)
LogEntry ("sent {0} to {1}".format(strCmd,strHostname))
strOut = stdout.read()
SSH.close()
strOut = strOut.decode("utf-8")
strOutFile = strOutPath + strHostname + ".txt"
if strHostname in dictDevices:
objFileOut = open(strOutFile,"a")
else:
objFileOut = open(strOutFile,"w")
objFileOut.write (strCmd + "\n" + strOut + "\n")
objFileOut.close()
LogEntry ("output written to "+strOutFile)
except paramiko.ssh_exception.AuthenticationException as err:
LogEntry ("Auth Exception: {0}".format(err))
strOut = "Auth Exception: {0}".format(err)
except paramiko.SSHException as err:
LogEntry ("SSH Exception: {0}".format(err))
strOut = "SSH Exception: {0}".format(err)
except OSError as err:
LogEntry ("Socket Exception: {0}".format(err))
strOut = "Socket Exception: {0}".format(err)
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
strOut = "Generic Exception: {0}".format(err)
return strOut
#end function GetResults
def ValidateRetry(strHostname,strCmd):
global iErrCount
global FailedDevs
global lstFailedDevsName
global iAuthFail
global strPWD
global strUserName
global bDevOK
strOut = GetResults(strHostname,strCmd)
while "Exception" in strOut and iErrCount < iMaxError:
if "SSH Exception:" in strOut or "Socket Exception:" in strOut:
iErrCount += 1
LogEntry ("Trying again in 5 sec")
time.sleep(5)
elif "Auth Exception" in strOut:
playsound(r'c:\windows\media\tada.wav')
strUserName = getInput("Please provide username for use when login into the routers, enter to use {}: ".format(DefUserName))
if strUserName == "":
strUserName = DefUserName
# end if username is empty
strPWD = getpass.getpass(prompt="what is the password for {0}: ".format(strUserName))
if strPWD == "":
print ("empty password, next device")
iErrCount = iMaxError
break
iAuthFail += 1
if iAuthFail == iMaxAuthFail:
iErrCount = iMaxError
else:
LogEntry("Unknown exception {}\n Next Device!".format(strOut))
iErrCount = iMaxError
break
strOut = GetResults(strHostname,strCmd)
if "Exception" in strOut:
if not bFailedDev:
FailedDevs.append(iInputLineNum)
lstFailedDevsName.append(strHostname)
bDevOK = False
LogEntry ("Exceeded Max Retry's, next device!")
else:
bDevOK = True
return strOut
# end function ValidateRetry
def LogEntry(strMsg):
strTimeStamp = time.strftime("%m-%d-%Y %H:%M:%S")
objLogOut.write("{0} : {1}\n".format(strTimeStamp,strMsg))
print (strMsg)
def StatusUpdate():
tElapse = time.time()
iElapseSec = tElapse - tStart
ieMin, ieSec = divmod(iElapseSec, 60)
ieHours, ieMin = divmod(ieMin, 60)
if ieHours == 0:
if ieMin == 0:
strElapse = "Elapse time {:.2f} seconds.".format(ieSec)
else:
strElapse = "Elapse time {} minutes.".format(int(ieMin))
else:
strElapse = "Elapse time {} hours and {} minutes.".format(int(ieHours),int(ieMin))
if iPercentComplete > 0:
iEstRemainSec = (iElapseSec/iPercentComplete)-iElapseSec
iMin, iSec = divmod(iEstRemainSec, 60)
iHours, iMin = divmod(iMin, 60)
if iHours == 0:
if iMin == 0:
strEstRemain = "Estimated time left {:.2f} seconds. ".format(iSec)
else:
strEstRemain = "Estimated time left {} minutes. ".format(int(iMin))
else:
strEstRemain = "Estimated time left {} hours and {} minutes. ".format(int(iHours),int(iMin))
else:
strEstRemain = ""
return strEstRemain + strElapse
def OSDetect():
strHostVer = "Unknown"
strOut = ValidateRetry(strHostname,"show version")
for strOS in dictBaseCmd:
if dictBaseCmd[strOS]["Match"] in strOut:
strHostVer = strOS
if strOS == "IOS":
continue
if strHostVer == "Unknown" :
if dictBaseCmd["IOS"]["Match"] in strOut:
if dictBaseCmd["IOS"]["Match"] in strOut:
strHostVer = "IOS"
return strHostVer
def IPv4Peers():
dictIPv4Peers={}
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-GT-Summary"])
dictIPv4Peers = AnalyzeIPv4Results(strOut.splitlines(),"Global Table")
for strVRF in lstVRFs:
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-VRF-Summary"].format(strVRF))
dictTemp = AnalyzeIPv4Results(strOut.splitlines(),strVRF)
dictIPv4Peers.update(dictTemp)
if bFailedDev:
LogEntry ("Retrying {}, {} failed devices left to retry.".format(strHostname,len(lstFailedDevsName)-1))
else:
LogEntry ("{0} is device {1} out of {2}. Completed {3:.1%} {4}".format(strHostname,iInputLineNum - 1,iDevCount,iPercentComplete,StatusUpdate()))
LogEntry ("Gathering details on {} IPv4 Peers.".format(len(dictIPv4Peers)))
iCurPeer = 0
for strPeerIP in dictIPv4Peers:
iCurPeer += 1
LogEntry ("IPv4 Peer {} out of {}".format(iCurPeer,len(dictIPv4Peers)))
strVRF = dictIPv4Peers[strPeerIP]["VRF"]
iLineNum = dictIPv4Peers[strPeerIP]["LineID"]
if strVRF == "Global Table":
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-GT-Description"].format(strPeerIP))
strDescr = ParseDescr(strOut.splitlines(), iLineNum)
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-GT-Receive"].format(strPeerIP))
AnalyzeIPv4Routes(strOut.splitlines(),strVRF,strPeerIP,strHostname,strDescr,iLineNum)
else:
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-VRF-Description"].format(strVRF,strPeerIP))
strDescr = ParseDescr(strOut.splitlines(), iLineNum)
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv4-VRF-Receive"].format(strVRF,strPeerIP))
AnalyzeIPv4Routes(strOut.splitlines(),strVRF,strPeerIP,strHostname,strDescr,iLineNum)
if bFailedDev:
LogEntry ("Retrying {}, {} failed devices left to retry.".format(strHostname,len(lstFailedDevsName)-1))
else:
LogEntry ("{} is device {} out of {}. Completed {:.1%} {}".format(strHostname,iInputLineNum - 1,iDevCount,iPercentComplete,StatusUpdate()))
def IPv6Peers():
dictIPv6Peers={}
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-GT-Summary"])
dictIPv6Peers = AnalyzeIPv6Results(strOut.splitlines(),"Global Table")
for strVRF in lstVRFs:
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-VRF-Summary"].format(strVRF))
dictTemp = AnalyzeIPv6Results(strOut.splitlines(),strVRF)
dictIPv6Peers.update(dictTemp)
if bFailedDev:
LogEntry ("Retrying {}, {} failed devices left to retry.".format(strHostname,len(lstFailedDevsName)-1))
else:
LogEntry ("{} is device {} out of {}. Completed {:.1%} {}".format(strHostname,iInputLineNum - 1,iDevCount,iPercentComplete,StatusUpdate()))
LogEntry ("Gathering details on {} IPv6 Peers.".format(len(dictIPv6Peers)))
iCurPeer = 0
for strPeerIP in dictIPv6Peers:
iCurPeer += 1
LogEntry ("IPv6 Peer {} out of {}".format(iCurPeer,len(dictIPv6Peers)))
if strPeerIP == "":
continue
strVRF = dictIPv6Peers[strPeerIP]["VRF"]
iLineNum = dictIPv6Peers[strPeerIP]["LineID"]
if strVRF == "Global Table":
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-GT-Description"].format(strPeerIP))
strDescr = ParseDescr(strOut.splitlines(), iLineNum)
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-GT-Receive"].format(strPeerIP))
AnalyzeIPv6Routes(strOut.splitlines(),strVRF,strPeerIP,strHostname,strDescr,iLineNum)
else:
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-VRF-Description"].format(strVRF,strPeerIP))
strDescr = ParseDescr(strOut.splitlines(), iLineNum)
strOut = ValidateRetry(strHostname,dictBaseCmd[strHostVer]["IPv6-VRF-Receive"].format(strVRF,strPeerIP))
AnalyzeIPv6Routes(strOut.splitlines(),strVRF,strPeerIP,strHostname,strDescr,iLineNum)
if bFailedDev:
LogEntry ("Retrying {}, {} failed devices left to retry.".format(strHostname,len(lstFailedDevsName)-1))
else:
LogEntry ("{} is device {} out of {}. Completed {:.1%} {}".format(strHostname,iInputLineNum - 1,iDevCount,iPercentComplete,StatusUpdate()))
DefUserName = getpass.getuser()
print ("This is a router audit script. Your default username is {3}. This is running under Python Version {0}.{1}.{2}".format(sys.version_info[0],sys.version_info[1],sys.version_info[2],DefUserName))
now = time.asctime()
print ("The time now is {}".format(now))
print ("This script will read a source excel sheet and log into each router listed in the identified column,\n"
"starting with row 2, execute defined command and write results across multiple tabs")
for strOS in dictBaseCmd:
for attr in lstRequiredElements:
if attr not in dictBaseCmd[strOS]:
print ("{} is missing definition for {}.\n *** Each OS version requires definitions for the following:\n{}".format(strOS,attr,lstRequiredElements))
sys.exit(5)
getInput ("Press enter to bring up a file open dialog so you may choose the source Excel file")
root = tk.Tk()
root.withdraw()
strWBin = filedialog.askopenfilename(title = "Select spreadsheet",filetypes = (("Excel files","*.xlsx"),("Text Files","*.txt"),("All Files","*.*")))
if strWBin =="":
print ("You cancelled so I'm exiting")
sys.exit(2)
#end if no file
strWBin = strWBin.replace("/","\\")
print ("You selected: " + strWBin)
print ("File extention is:{}".format(strWBin[-4:]))
if strWBin[-4:] != "xlsx" :
print ("I was expecting an excel input file with xlsx extension. Don't know what do to except exit")
sys.exit(2)
#end if xlsx
iLoc = strWBin.rfind("\\")
strPath = strWBin[:iLoc]
iLoc = strWBin.rfind(".")
strLogFile = strWBin[:iLoc]+".log"
objLogOut = open(strLogFile,"w",1)
LogEntry("Started logging to {}".format(strLogFile))
strOutPath = strPath+"\\"+strOutFolderName+"\\"
if not os.path.exists (strOutPath) :
os.makedirs(strOutPath)
print ("\nPath '{0}' for output files didn't exists, so I create it!\n".format(strOutPath))
print ("Opening that spreadsheet, please stand by ...")
app = win32.gencache.EnsureDispatch('Excel.Application')
app.Visible = True
wbin = app.Workbooks.Open (strWBin,0,False)
print ("I will be gathering all BGP peers and what is being received over them:\n")
print ("Here is a list of sheets in this spreadsheet:")
iSheetCount = wbin.Worksheets.Count
for i in range(1,iSheetCount+1):
strTemp = wbin.Worksheets(i).Name
dictSheets[strTemp]=i
if strTemp == strSummarySheet :
iResultNum = i
continue
if strTemp == strDetailSheet :
iResult2Num = i
continue
if strTemp == strPrefixeSheet :
iResult3Num = i
continue
print ("{0}) {1}".format(i,strTemp))
# end for loop
i += 1
print ("{}) So sorry, wrong file, please exist".format(i))
strSelect = getInput("Which of the above choices is the input sheet: ")
try:
iSelect = int(strSelect)
except ValueError:
print("Invalid choice: '{}'".format(strSelect))
iSelect = i
if iSelect < 1 or iSelect > i :
print("Invalid choice: {}".format(iSelect))
iSelect = i
if iSelect == iResultNum or iSelect == iResult2Num or iSelect == iResult3Num:
print("Sorry that is the results sheet, not the input sheet.")
iSelect = i
if iSelect == i :
sys.exit(1)
wsInput = wbin.Worksheets(iSelect)
print ("Input sheet '{}' activated".format(wsInput.Name))
print ("Here is a preview of the data in that sheet")
iCol = 1
while wsInput.Cells(1,iCol).Value != "" and wsInput.Cells(1,iCol).Value != None :
print ("{0}) {1}".format(iCol,wsInput.Cells(1,iCol).Value))
print (" {0}".format(wsInput.Cells(2,iCol).Value))
print (" {0}".format(wsInput.Cells(3,iCol).Value))
iCol += 1
print ("{}) So sorry, wrong file, please exist".format(iCol))
strSelect = getInput("Please select the column with the list of router: ")
try:
iInputColumn = int(strSelect)
except ValueError:
print("Invalid choice: '{}'".format(strSelect))
iInputColumn = iCol
if iInputColumn < 1 or iInputColumn > iCol :
print("Invalid choice: {}".format(iInputColumn))
iInputColumn = iCol
if iInputColumn == iCol :
sys.exit(1)
# wbin.Worksheets(1).Activate
if strSummarySheet in dictSheets:
strSelect = getInput("Summary sheet '{}' exists, is it OK to overwrite (y/n): ".format(strSummarySheet))
strSelect = strSelect.lower()
if strSelect == "":
strSelect = "y"
print ("Blank input assuming yes")
if strSelect[0] == "y":
wsResult = wbin.Worksheets(strSummarySheet)
wsResult.Range(wsResult.Columns(1),wsResult.Columns(15)).Clear()
else:
print ("No problem at all, exiting so you can rename, etc.")
sys.exit(1)
else:
print ("Summary sheet not found, creating one")
wbin.Sheets.Add(After=wsInput)
wsResult = wbin.ActiveSheet
wsResult.Name = strSummarySheet
if strDetailSheet in dictSheets:
strSelect = getInput("Detail sheet '{}' exists, is it OK to overwrite (y/n): ".format(strDetailSheet))
strSelect = strSelect.lower()
if strSelect == "":
strSelect = "y"
print ("Blank input assuming yes")
if strSelect[0] == "y":
wsDetails = wbin.Worksheets(strDetailSheet)
wsDetails.Range(wsDetails.Columns(1),wsDetails.Columns(15)).Clear()
else:
print ("No problem at all, exiting so you can rename, etc.")
sys.exit(1)
else:
print ("Detail sheet not found, creating one")
wbin.Sheets.Add(After=wsResult)
wsDetails = wbin.ActiveSheet
wsDetails.Name = strDetailSheet
if strPrefixeSheet in dictSheets:
strSelect = getInput("Prefix sheet '{}' exists, is it OK to overwrite (y/n): ".format(strPrefixeSheet))
strSelect = strSelect.lower()
if strSelect == "":
strSelect = "y"
print ("Blank input assuming yes")
if strSelect[0] == "y":
wsPrefixes = wbin.Worksheets(strPrefixeSheet)
wsPrefixes.Range(wsPrefixes.Columns(1),wsPrefixes.Columns(555)).Clear()
else:
print ("No problem at all, exiting so you can rename, etc.")
sys.exit(1)
else:
print ("Prefix sheet not found, creating one")
wbin.Sheets.Add(After=wsDetails)
wsPrefixes = wbin.ActiveSheet
wsPrefixes.Name = strPrefixeSheet
iInputLineNum = 2
while wsInput.Cells(iInputLineNum,iInputColumn).Value != "" and wsInput.Cells(iInputLineNum,iInputColumn).Value != None :
iInputLineNum += 1
iDevCount = iInputLineNum-2
wsResult.Select()
LogEntry("BGP Summary tab activated")
print ("There are {} devices listed in sheet '{}' column {}".format(iDevCount,wsInput.Name,iInputColumn))
strUserName = getInput("Please provide username for use when login into the routers, enter to use {}: ".format(DefUserName))
if strUserName == "":
strUserName = DefUserName
# end if username is empty
strPWD = getpass.getpass(prompt="what is the password for {0}: ".format(strUserName))
if strPWD == "":
print ("empty password, exiting")
sys.exit(5)
ResultHeaders()
iInputLineNum = 2
iOutLineNum = 1
iOut2Line = 1
strHostname = wsInput.Cells(iInputLineNum,iInputColumn).Value
FailedDevs = []
lstFailedDevsName = []
bDevOK = True
bFailedDev = False
while strHostname != "" and strHostname != None :
iErrCount = 0
iAuthFail = 0
strHostname = strHostname.upper()
LogEntry ("Processing {} ...".format(strHostname))
iPercentComplete = (iInputLineNum - 2)/iDevCount
LogEntry ("Device {0} out of {1}. Completed {2:.1%} {3}".format(iInputLineNum - 1,iDevCount,iPercentComplete,StatusUpdate()))
strHostVer = OSDetect()
LogEntry ("Found IOS version to be {}".format(strHostVer))
dictDevices[strHostname] = strHostVer
if strHostVer == "Unknown":
LogEntry("Can't process unknown platform")
if bDevOK:
try:
iOutLineNum += 1
wsResult.Cells(iOutLineNum,1).Value = strHostname
wsResult.Cells(iOutLineNum,2).Value = strHostVer
except Exception as err:
LogEntry ("Generic Exception: {0}".format(err))
iInputLineNum += 1
strHostname = wsInput.Cells(iInputLineNum,iInputColumn).Value
continue
if bDevOK: