I have a python script that grabs all IP from the arp table and assign it to a variable. I have for loop that creates another two variables start_IP containing the first IP of a subnet and last_IP containing the last IP in that same subnet. For each loop I will have a different start and last IPs.
I am trying to do check the variable containing all IPs and see how many IPs fall under each subnet.
What would be the best way to do this? Here is a hardcoded example: count = 0
arps = ['10.20.30.130','10.20.30.131','10.20.30.132', '10.20.30.133',
'10.20.30.136', '10.20.30.137', '10.20.30.138', '10.20.30.139', '10.20.30.140', '10.20.30.141', '10.20.30.143', '10.20.30.149']
start_ip = "10.20.30.132"
end_ip = "10.20.30.142"
count = 0
for arp in arps:
if arp >= start_ip and arp <= end_ip:
count = count + 1
print count
else:
continue
print "Count: ", count
Is there a better an faster way of doing this?