def summarize_address_range(first, last):
 if (not (isinstance(first, _BaseAddress) and isinstance(last, _BaseAddress))):
  raise TypeError(u'first and last must be IP addresses, not networks')
 if (first.version != last.version):
  raise TypeError((u'%s and %s are not of the same version' % (first, last)))
 if (first > last):
  raise ValueError(u'last IP address must be greater than first')
 if (first.version == 4):
  ip = IPv4Network
 elif (first.version == 6):
  ip = IPv6Network
 else:
  raise ValueError(u'unknown IP version')
 ip_bits = first._max_prefixlen
 first_int = first._ip
 last_int = last._ip
 while (first_int <= last_int):
  nbits = min(_count_righthand_zero_bits(first_int, ip_bits), (_compat_bit_length(((last_int - first_int) + 1)) - 1))
  net = ip((first_int, (ip_bits - nbits)))
  (yield net)
  first_int += (1 << nbits)
  if ((first_int - 1) == ip._ALL_ONES):
   break

def summarize_address_range ( first , last ) : if ( not ( isinstance ( first , _BaseAddress ) and isinstance ( last , _BaseAddress ) ) ) : raise TypeError ( u'first and last must be IP addresses, not networks' ) if ( first . version != last . version ) : raise TypeError ( ( u'%s and %s are not of the same version' % ( first , last ) ) ) if ( first > last ) : raise ValueError ( u'last IP address must be greater than first' ) if ( first . version == 4 ) : ip = IPv4Network elif ( first . version == 6 ) : ip = IPv6Network else : raise ValueError ( u'unknown IP version' ) ip_bits = first . _max_prefixlen first_int = first . _ip last_int = last . _ip while ( first_int <= last_int ) : nbits = min ( _count_righthand_zero_bits ( first_int , ip_bits ) , ( _compat_bit_length ( ( ( last_int - first_int ) + 1 ) ) - 1 ) ) net = ip ( ( first_int , ( ip_bits - nbits ) ) ) ( yield net ) first_int += ( 1 << nbits ) if ( ( first_int - 1 ) == ip . _ALL_ONES ) : break
summarize a network range given the first and last ip addresses .