title: Python - Best way to count IPs that fall under IP range
body: <p>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.</p>
  
  <p>I am trying to do check the variable containing all IPs and see how many IPs fall under each subnet.  </p>
  
  <p>What would be the best way to do this?  Here is a hardcoded example:
  count = 0</p>
  
  <pre><code>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 &gt;= start_ip and arp &lt;= end_ip:
          count = count + 1
          print count
      else:
          continue
  
   print "Count: ", count
  </code></pre>
  
  <p>Is there a better an faster way of doing this?</p>