def _bsd_ranges():
    pp = subprocess.Popen(['sysctl', 'net.inet.ip.portrange'], stdout=subprocess.PIPE)
    stdout, stderr = pp.communicate()
    lines = stdout.decode('ascii').split('\n')
    out = dict([[x.strip().rsplit('.')[-1] for x in l.split(':')] for l in lines if l])

    ranges = [
        # FreeBSD & Mac
        ('first', 'last'),
        ('lowfirst', 'lowlast'),
        ('hifirst', 'hilast'),
        # OpenBSD
        ('portfirst', 'portlast'),
        ('porthifirst', 'porthilast'),
    ]

    res = []
    for rng in ranges:
        try:
            low, high = int(out[rng[0]]), int(out[rng[1]])
            if low <= high:
                res.append((low, high))
        except __HOLE__:
            pass
    return res
dataset/ETHPy150Open kmike/port-for/port_for/ephemeral.py/_bsd_ranges