How to use the openpyn.api function in openpyn

To help you get started, we’ve selected a few openpyn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jotyGill / openpyn-nordvpn / openpyn / openpyn.py View on Github external
# check if OpenVPN config files exist if not download them.
    check_config_files()

    # if only positional argument used
    if country_code is None and server is None:
        country_code = country      # consider the positional arg e.g "us" same as "-c us"
    # if either "-c" or positional arg f.e "au" is present
    if country_code:
        # ask for and store credentials if not present, skip if "--test"
        if not test:
            if credentials.check_credentials() is False:
                credentials.save_credentials()

        if len(country_code) > 2:   # full country name
            # get the country_code from the full name
            country_code = api.get_country_code(full_name=country_code)
        country_code = country_code.lower()

        # keep trying to connect to new servers
        for tries in range(3):  # pylint: disable=W0612
            better_servers_list = find_better_servers(
                country_code, area, max_load, top_servers, tcp, p2p,
                dedicated, double_vpn, tor_over_vpn, anti_ddos, netflix, location, stats)
            pinged_servers_list = ping_servers(better_servers_list, pings, stats)
            chosen_servers = choose_best_servers(pinged_servers_list, stats)

            # connect to chosen_servers, if one fails go to next
            for aserver in chosen_servers:
                if stats:
                    print(Style.BRIGHT + Fore.BLUE + "Out of the Best Available Servers, Chose",
                          (Fore.GREEN + aserver + Fore.BLUE) + "\n")
                # if "-f" used apply firewall rules
github jotyGill / openpyn-nordvpn / openpyn / initd.py View on Github external
skip_dns_patch = True
        elif os.path.exists("/etc/openwrt_release"):
            silent = True
            skip_dns_patch = True

    openpyn_options = ""

    # if only positional argument used
    if country_code is None and server is None:
        country_code = country      # consider the positional arg e.g "us" same as "-c us"
    # if either "-c" or positional arg f.e "au" is present

    if country_code:
        if len(country_code) > 2:   # full country name
            # get the country_code from the full name
            country_code = api.get_country_code(full_name=country_code)
        country_code = country_code.lower()
        openpyn_options += country_code

    elif server:
        openpyn_options += " --server " + server

    if area:
        openpyn_options += " --area " + area
    if tcp:
        openpyn_options += " --tcp"
    if max_load:
        openpyn_options += " --max-load " + str(max_load)
    if top_servers:
        openpyn_options += " --top-servers " + str(top_servers)
    if pings:
        openpyn_options += " --pings " + str(pings)
github jotyGill / openpyn-nordvpn / openpyn / asus.py View on Github external
def run(server, c_code, client, rgw=None, comp=None, adns=None, tcp=False, test=False, debug=False):
    with open(__basefilepath__ + "credentials", 'r') as f:
        lines = f.read().splitlines()
        f.close()

    url = "https://api.nordvpn.com/server"
    json_response = api.get_json(url)
    for res in json_response:
        if res["domain"][:2].lower() == c_code.lower():
            country_name = res["country"]
            break

    port = "udp"
    port_name = "1194"
    protocol_name = "udp"
    folder = "ovpn_udp/"
    if tcp:
        port = "tcp"
        port_name = "443"
        protocol_name = "tcp-client"
        folder = "ovpn_tcp/"

    vpn_config_file = server + ".nordvpn.com." + port + ".ovpn"
github jotyGill / openpyn-nordvpn / openpyn / openpyn.py View on Github external
return 1

        if not root.verify_running_as_root():
            logger.error("Please run '--daemon' or '-d' mode with sudo")
            return 1
        openpyn_options = ""

        # if only positional argument used
        if country_code is None and server is None:
            country_code = country      # consider the positional arg e.g "us" same as "-c us"
        # if either "-c" or positional arg f.e "au" is present

        if country_code:
            if len(country_code) > 2:   # full country name
                # get the country_code from the full name
                country_code = api.get_country_code(full_name=country_code)
            country_code = country_code.lower()
            openpyn_options += country_code

        elif server:
            openpyn_options += " --server " + server

        if area:
            openpyn_options += " --area " + area
        if tcp:
            openpyn_options += " --tcp"
        if max_load:
            openpyn_options += " --max-load " + str(max_load)
        if top_servers:
            openpyn_options += " --top-servers " + str(top_servers)
        if pings:
            openpyn_options += " --pings " + str(pings)