Skip to content
This repository was archived by the owner on Nov 5, 2025. It is now read-only.

Commit a90eb51

Browse files
committed
Add country code exclusion in connect command
1 parent 494ccd9 commit a90eb51

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

protonvpn_cli/cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def connect(self):
115115
group.add_argument("-f", "--fastest", help="Connect to the fastest ProtonVPN server.", action="store_true")
116116
group.add_argument("-r", "--random", help="Connect to a random ProtonVPN server.", action="store_true")
117117
group.add_argument("--cc", help="Connect to the specified country code (SE, PT, BR, AR).", metavar="")
118+
group.add_argument("--not-cc", help="Connect to the fastest server not inside the specified country code (SE, PT, BR, AR).", metavar="")
118119
group.add_argument("--sc", help="Connect to the fastest Secure-Core server.", action="store_true")
119120
group.add_argument("--p2p", help="Connect to the fastest torrent server.", action="store_true")
120121
group.add_argument("--tor", help="Connect to the fastest Tor server.", action="store_true")
@@ -138,6 +139,8 @@ def connect(self):
138139
connection.direct(args.servername, protocol)
139140
elif args.cc:
140141
connection.country_f(args.cc, protocol)
142+
elif args.not_cc:
143+
connection.country_f(args.not_cc, protocol, True)
141144
elif args.p2p:
142145
connection.feature_f(self.server_features_dict.get("p2p", None), protocol)
143146
elif args.sc:
@@ -341,6 +344,9 @@ def print_examples():
341344
"protonvpn connect --cc AU\n"
342345
" Connect to the fastest Australian server\n"
343346
" with the default protocol.\n\n"
347+
"protonvpn connect --not-cc AU\n"
348+
" Connect to the fastest server outside Australia\n"
349+
" with the default protocol.\n\n"
344350
"protonvpn c --p2p -p tcp\n"
345351
" Connect to the fastest torrent server with TCP.\n\n"
346352
"protonvpn c --sc\n"

protonvpn_cli/connection.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def fastest(protocol=None):
165165
openvpn_connect(fastest_server, protocol)
166166

167167

168-
def country_f(country_code, protocol=None):
168+
def country_f(country_code, protocol=None, excluded=False):
169169
"""Connect to the fastest server in a specific country."""
170170
logger.debug("Starting fastest country connect")
171171

@@ -185,15 +185,23 @@ def country_f(country_code, protocol=None):
185185
# Filter out excluded features and countries
186186
server_pool = []
187187
for server in servers:
188-
if server["Features"] not in excluded_features and server["ExitCountry"] == country_code:
189-
server_pool.append(server)
188+
if server["Features"] not in excluded_features:
189+
if (excluded and server["ExitCountry"] != country_code) or (not excluded and server["ExitCountry"] == country_code):
190+
server_pool.append(server)
190191

191192
if len(server_pool) == 0:
192-
print(
193-
"[!] No Server in country {0} found\n".format(country_code)
194-
+ "[!] Please choose a valid country"
195-
)
196-
logger.debug("No server in country {0}".format(country_code))
193+
if not excluded:
194+
print(
195+
"[!] No Server in country {0} found\n".format(country_code)
196+
+ "[!] Please choose a valid country"
197+
)
198+
logger.debug("No server in country {0}".format(country_code))
199+
else:
200+
print(
201+
"[!] No Server found outside country {0}\n".format(country_code)
202+
+ "[!] Please choose a valid country"
203+
)
204+
logger.debug("No server outside country {0}".format(country_code))
197205
sys.exit(1)
198206

199207
fastest_server = get_fastest_server(server_pool)

protonvpn_cli/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
protonvpn (c | connect) [<servername>] [-p <protocol>]
2828
protonvpn (c | connect) [-f | --fastest] [-p <protocol>]
2929
protonvpn (c | connect) [--cc <code>] [-p <protocol>]
30+
protonvpn (c | connect) [--not-cc <code>] [-p <protocol>]
3031
protonvpn (c | connect) [--sc] [-p <protocol>]
3132
protonvpn (c | connect) [--p2p] [-p <protocol>]
3233
protonvpn (c | connect) [--tor] [-p <protocol>]
@@ -44,6 +45,7 @@
4445
-f, --fastest Select the fastest ProtonVPN server.
4546
-r, --random Select a random ProtonVPN server.
4647
--cc CODE Determine the country for fastest connect.
48+
--not-cc CODE Determine the country to exclude for fastest connect.
4749
--sc Connect to the fastest Secure-Core server.
4850
--p2p Connect to the fastest torrent server.
4951
--tor Connect to the fastest Tor server.

0 commit comments

Comments
 (0)