def _write_unassigned_ranges(out_filename): """ Downloads ports data from IANA & Wikipedia and converts it to a python module. This function is used to generate _ranges.py. """ with open(out_filename, 'wt') as f: f.write('# auto-generated by port_for._download_ranges (%s)\n' % datetime.date.today()) f.write('UNASSIGNED_RANGES = [\n') for range in to_ranges(sorted(list(_unassigned_ports()))): f.write(" (%d, %d),\n" % range) f.write(']\n')
def good_port_ranges(ports=None, min_range_len=20, border=3): """ Returns a list of 'good' port ranges. Such ranges are large and don't contain ephemeral or well-known ports. Ranges borders are also excluded. """ min_range_len += border*2 if ports is None: ports = available_ports() ranges = utils.to_ranges(list(ports)) lenghts = sorted([(r[1]-r[0], r) for r in ranges], reverse=True) long_ranges = [l[1] for l in lenghts if l[0] >= min_range_len] without_borders = [(low+border, high-border) for low, high in long_ranges] return without_borders
def good_port_ranges(ports=None, min_range_len=20, border=3): """ Returns a list of 'good' port ranges. Such ranges are large and don't contain ephemeral or well-known ports. Ranges borders are also excluded. """ min_range_len += border * 2 if ports is None: ports = available_ports() ranges = utils.to_ranges(list(ports)) lenghts = sorted([(r[1] - r[0], r) for r in ranges], reverse=True) long_ranges = [l[1] for l in lenghts if l[0] >= min_range_len] without_borders = [(low + border, high - border) for low, high in long_ranges] return without_borders