I'm a beginner.
Could you tell me why this script works even though the i variable is not defined in the ip not in i case?
The script compares a list of ARP table match_data (which I get from a paramiko ssh connection), and my ip list match_ip. I just want to print the IP MAC, and if the IP is not in the ARP list table to print ip + "NO MAC ADDRESS".
for ip in match_ip:
for i in match_data:
if ip in i:
print re.search((ip+'\s+'),i).group(0),mac.search(i).group(0)
break
if ip not in i:
print ip + ' NO MAC ADDRESS'
Output
C:\Python27\python.exe C:/Python2/Get_mac_from_arp.py
!!!Connecting SSH!!!
10.240.184.103 30e4.db80.b699
10.240.184.104 7c2f.802d.61e5
10.240.184.105 7c2f.8072.40fc
10.240.184.106 e05f.b982.5720
10.240.178.11 NO MAC ADDRESS
10.240.184.177 e05f.b982.5752
10.240.184.178 7c2f.802a.782a
10.240.184.179 30e4.db80.b6ec
10.240.184.180 7c2f.802a.782b
Process finished with exit code 0
(ip not in i)case".istill has the value it had at the end of theforloop.iinif ip not in i:takes the last value ofiit had infor i in match_data:iis a very poor name for this variable