def vpn(base, prefer, approx, includes=None, excludes=None):
    """
    Generate networks for VPN route table.
    """
    def load_networks(path_arr):
        if path_arr:
            ret = IPSet()
            for path in path_arr.split(','):
                ret |= networks_from_source(open(path, 'rb').read())
            return ret

    must_include = load_networks(includes)
    must_exclude = private_networks()
    if excludes:
        must_exclude |= load_networks(excludes)
    base_networks = china_networks() if base == 'china' else foreign_networks()
    networks = approx_networks(
        base_networks,
        prefer == 'include',
        approx,
        must_include,
        must_exclude
    )
    print '\n'.join(map(str, networks.iter_cidrs()))
def china():
    """Query about the china networks."""
    networks = china_networks()
    print '\n'.join(map(str, networks.iter_cidrs()))
예제 #3
0
파일: utility.py 프로젝트: korepwx/gfwtools
def foreign_networks():
    return negate_networks(china_networks() | private_networks())