-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmullvad_cli_wrapper.py
1580 lines (1487 loc) · 63.4 KB
/
mullvad_cli_wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import warnings
from typing import Literal
import invoke
from invoke import run, UnexpectedExit, Failure, ThreadException, Result
class VersionWarning(Warning):
"""Class for warnings about version mismatches."""
def __init__(self, *args, **kwargs):
pass
class MullvadCLIWrapper:
WRAPPER_VERSION = "2024.5"
f"""
Built on mullvad-cli {WRAPPER_VERSION}
"""
CLI_VERSION = run("mullvad --version", hide="both").stdout.split(" ")[1]
if WRAPPER_VERSION != CLI_VERSION:
warnings.warn(
f"The installed mullvad-cli version is '{CLI_VERSION}'. This wrapper was built for version {WRAPPER_VERSION}. The command line options may have changed.",
VersionWarning,
)
def mullvad_account_create(
self, hide: bool | str = True, **kwargs
) -> invoke.Result:
"""
Create and log in on a new account
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account create", hide=hide, **kwargs)
def mullvad_account_login(
self, account: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Log in on an account
:param account: The Mullvad account token to configure the client with
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account login", options=account, hide=hide, **kwargs)
def mullvad_account_logout(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Log out of the current account
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account logout", hide=hide, **kwargs)
def mullvad_account_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display information about the current account
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account get", hide=hide, **kwargs)
def mullvad_account_list_devices(
self, account: str = "", hide: bool = True, **kwargs
) -> invoke.Result:
"""
List devices associated with an account
:param account: Mullvad account number (current account if not specified)
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad account list-devices", options=account, hide=hide, **kwargs
)
def mullvad_account_revoke_devices(
self, device: str = "", hide: bool = True, **kwargs
) -> invoke.Result:
"""
Revoke a device associated with an account
:param device: Name or UID of the device to revoke
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad account revoke-device", options=device, hide=hide, **kwargs
)
def mullvad_account_redeem(
self, voucher: str = "", hide: bool = True, **kwargs
) -> invoke.Result:
"""
Redeem a voucher
:param voucher: Name or UID of the device to revoke
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account redeem", options=voucher, hide=hide, **kwargs)
def mullvad_auto_connect_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current auto-connect setting
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad auto-connect get", hide=hide, **kwargs)
def mullvad_auto_connect_set(
self, policy: Literal["on", "off"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Change auto-connect setting
:param policy: One of "on" or "off"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad auto-connect set", options=policy, hide=hide, **kwargs)
def mullvad_beta_program_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Get beta notifications setting
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad beta-program get", hide=hide, **kwargs)
def mullvad_beta_program_set(
self, policy: Literal["on", "off"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Change beta notifications setting
:param policy: One of "on" or "off"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad beta-program set", options=policy, hide=hide, **kwargs)
def mullvad_lockdown_mode_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current lockdown mode setting
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad lockdown-mode get", hide=hide, **kwargs)
def mullvad_lockdown_mode_set(
self, policy: Literal["on", "off"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Change the lockdown mode setting
:param policy: One of "on" or "off"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad lockdown-mode set", options=policy, hide=hide, **kwargs
)
def mullvad_dns_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current DNS settings
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad lockdown-mode get", hide=hide, **kwargs)
def mullvad_dns_set_default(
self,
options: list[
Literal[
"--block-ads",
"--block-trackers",
"--block-malware",
"--block-adult-content",
"--block-gambling",
"--block-social-media",
]
],
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Use a default DNS server, with or without content blocking
:param options: list[str] Content blocking options. Possible options:
[
"--block-ads",
"--block-trackers",
"--block-malware",
"--block-adult-content",
"--block-gambling",
"--block-social-media",
]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad dns set default", options=" ".join(options), hide=hide, **kwargs
)
def mullvad_dns_set_custom(
self,
servers: list[str],
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Set a list of custom DNS servers
:param servers: list[str] One or more IP addresses pointing to DNS resolvers
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad dns set custom", options=" ".join(servers), hide=hide, **kwargs
)
def mullvad_lan_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current local network sharing setting
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad lan get", hide=hide, **kwargs)
def mullvad_lan_set(
self, policy: Literal["allow", "block"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Change allow LAN setting
:param policy: One of "allow" or "block"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad lan set", options=policy, hide=hide, **kwargs)
def mullvad_connect(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Connect to a VPN relay
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad connect", hide=hide, **kwargs)
def mullvad_disconnect(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Disconnect from the VPN
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad disconnect", hide=hide, **kwargs)
def mullvad_reconnect(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Reconnect to any matching VPN relay
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad disconnect", hide=hide, **kwargs)
def mullvad_bridge_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Get current bridge settings
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad bridge get", hide=hide, **kwargs)
def mullvad_bridge_set_state(
self, policy: Literal["auto", "on", "off"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Specify whether to use a bridge
:param policy: One of "auto", "on" or "off"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad bridge set state", options=policy, hide=hide, **kwargs)
def mullvad_bridge_set_location(
self, location: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Set country or city to select relays from. Use the 'mullvad bridge list' command to show available alternatives
Select bridge using a country: mullvad bridge set location se
Select bridge using a country and city: mullvad bridge set location se got
Select bridge using a country, city and hostname: mullvad bridge set location se got se-got-br-001
Select bridge using only its hostname: mullvad bridge set location se-got-br-001
:param location: Any of the following
<COUNTRY> A two-letter country code, or 'any'
[CITY] A three-letter city code
[HOSTNAME] A host name, such as "se-got-wg-101"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set location", options=location, hide=hide, **kwargs
)
def mullvad_bridge_set_custom_list(
self, custom_list_name: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Set custom list to select relays from. Use the 'custom-lists list' command to show available alternatives
:param custom_list_name: str
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set custom-list",
options=custom_list_name,
hide=hide,
**kwargs,
)
def mullvad_bridge_set_provider(
self, provider: str = "any", hide: bool = True, **kwargs
) -> invoke.Result:
"""
Set hosting provider(s) to select relays from. The 'list' command shows the available relays and their providers
:param provider: str Either 'any', or provider to select from
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set provider", options=provider, hide=hide, **kwargs
)
def mullvad_bridge_set_ownership(
self, ownership: Literal["any", "owned", "rented"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Filter relays based on ownership. The 'list' command shows the available relays and whether they're rented
:param ownership: str Servers to select from: 'any', 'owned', or 'rented'
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set ownership", options=ownership, hide=hide, **kwargs
)
def mullvad_bridge_set_custom_set_socks5_local(
self,
local_port: str,
remote_ip: str,
remote_port: str,
transport_protocol: Literal["TCP", "UDP"] = "TCP",
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Registers a local SOCKS5 proxy. Will allow all local programs to leak traffic *only* to the remote endpoint.
:param local_port: str The port that the server on localhost is listening on
:param remote_ip: str The IP of the remote peer
:param remote_port: str The port of the remote peer
:param transport_protocol: str The Mullvad App can not know which transport protocol that the remote peer
accepts, but it needs to know this in order to correctly exempt the connection traffic in the firewall.
By default, the transport protocol is assumed to be `TCP`, but it can optionally be set to `UDP` as well.
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set custom set socks5 local",
options=f"{local_port} {remote_ip} {remote_port} --transport-protocol {transport_protocol}",
hide=hide,
**kwargs,
)
def mullvad_bridge_set_custom_set_socks5_remote(
self,
remote_ip: str,
remote_port: str,
username: str | None = None,
password: str | None = None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Configure a remote SOCKS5 proxy
:param remote_ip: str The IP of the remote proxy server
:param remote_port: str The port of the remote proxy server
:param username: str Username for authentication against a remote SOCKS5 proxy
:param password: str Password for authentication against a remote SOCKS5 proxy
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set custom set socks5 remote",
options=f"{remote_ip} {remote_port} {username if username else ' '} {password if password else ' '}",
hide=hide,
**kwargs,
)
def mullvad_bridge_set_custom_set_shadowsocks(
self,
remote_ip: str,
remote_port: str,
password: str,
cipher: (
Literal[
"aes-128-cfb",
"aes-128-cfb1",
"aes-128-cfb8",
"aes-128-cfb128",
"aes-256-cfb",
"aes-256-cfb1",
"aes-256-cfb8",
"aes-256-cfb128",
"rc4",
"rc4-md5",
"chacha20",
"salsa20",
"chacha20-ietf",
"aes-128-gcm",
"aes-256-gcm",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
"aes-128-pmac-siv",
"aes-256-pmac-siv",
]
| None
) = None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Configure bundled Shadowsocks proxy
:param remote_ip: str The IP of the remote Shadowsocks-proxy
:param remote_port: str Port on which the remote Shadowsocks-proxy listens for traffic
:param password: str Password for authentication
:param cipher: str Cipher to use [possible values: aes-128-cfb, aes-128-cfb1, aes-128-cfb8, aes-128-cfb128,
aes-256-cfb, aes-256-cfb1, aes-256-cfb8, aes-256-cfb128, rc4, rc4-md5, chacha20, salsa20, chacha20-ietf,
aes-128-gcm, aes-256-gcm, chacha20-ietf-poly1305, xchacha20-ietf-poly1305, aes-128-pmac-siv, aes-256-pmac-siv]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set custom set shadowsocks",
options=f"{remote_ip} {remote_port} {password} {'--ciper ' + cipher if cipher else ' '}",
hide=hide,
**kwargs,
)
def mullvad_bridge_set_custom_edit(
self,
username: str | None = None,
password: str | None = None,
cipher: str | None = None,
ip: str | None = None,
port: str | None = None,
local_port: str | None = None,
transport_protocol: str | None = None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Edit an existing custom bridge configuration
:param username: str Username for authentication \[Socks5 (Remote proxy)\]
:param password: str Password for authentication \[Socks5 (Remote proxy), Shadowsocks\]
:param cipher: str Cipher to use [possible values: aes-128-cfb, aes-128-cfb1, aes-128-cfb8, aes-128-cfb128,
aes-256-cfb, aes-256-cfb1, aes-256-cfb8, aes-256-cfb128, rc4, rc4-md5, chacha20, salsa20, chacha20-ietf,
aes-128-gcm, aes-256-gcm, chacha20-ietf-poly1305, xchacha20-ietf-poly1305, aes-128-pmac-siv, aes-256-pmac-siv]
:param ip: str The IP of the remote proxy server \[Socks5 (Local & Remote proxy), Shadowsocks\]
:param port: str The port of the remote proxy server \[Socks5 (Local & Remote proxy), Shadowsocks\]
:param local_port: str The port that the server on localhost is listening on \[Socks5 (Local proxy)\]
:param transport_protocol: str The transport protocol used by the remote proxy \[Socks5 (Local proxy)\]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad bridge set custom edit",
options=f"{'--username ' + username if username else ''} "
f"{'--password ' + password if password else ''} "
f"{'--ciper ' + cipher if cipher else ''} "
f"{'--ip ' + ip if ip else ''} "
f"{'--port ' + port if port else ''} "
f"{'--local-port ' + local_port if local_port else ''} "
f"{'--transport-protocol ' + transport_protocol if transport_protocol else ''}",
hide=hide,
**kwargs,
)
def mullvad_bridge_set_custom_use(
self, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Use an existing custom bridge configuration
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad bridge set custom use", hide=hide, **kwargs)
def mullvad_bridge_set_custom_disable(
self, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Stop using the custom bridge configuration
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad bridge set custom disable", hide=hide, **kwargs)
def mullvad_bridge_list(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
List available bridge relays
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account get", hide=hide, **kwargs)
def mullvad_relay_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current relay constraints
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad account get", hide=hide, **kwargs)
def mullvad_relay_set_location(
self,
country: str | None,
city: str | None,
hostname: str | None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Select a relay using country, city or hostname. The 'mullvad relay list' command shows the available relays and their geographical location
:param country: str A two-letter country code, or 'any'
:param city: str A three-letter city code
:param hostname: str A host name, such as "se-got-wg-101"
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
# input checks
if not any([country, hostname]):
raise ValueError(
"mullvad relay set location requires at least a country or hostname"
)
if all([country, hostname]):
raise ValueError(
"mullvad relay set location does not accept both a country and hostname"
)
return self.run(
f"mullvad relay set location",
options=f"{country} {city} {hostname}".strip(),
hide=hide,
**kwargs,
)
def mullvad_relay_set_custom_list(
self, custom_list: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Set custom list to select relays from. Use the 'custom-lists list' command to show available alternatives
:param custom_list: str Name of the custom list to use
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set custom-list", options=custom_list, hide=hide, **kwargs
)
def mullvad_relay_set_provider(
self, providers: list[str], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Set hosting provider(s) to select relays from. The 'list' command shows the available relays and their providers
:param providers: list[str] of providers
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set provider",
options=" ".join(providers),
hide=hide,
**kwargs,
)
def mullvad_relay_set_ownership(
self, ownership: Literal["any", "owned", "rented"], hide: bool = True, **kwargs
) -> invoke.Result:
"""
Filter relays based on ownership. The 'list' command shows the available relays and whether they're rented
:param ownership: str Servers to select from: 'any', 'owned', or 'rented'
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set ownership", options=ownership, hide=hide, **kwargs
)
def mullvad_relay_set_tunnel_openvpn(
self,
port: str,
transport_protocol: Literal["TCP", "UDP", "any"],
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Set OpenVPN-specific constraints
:param port: str Port to use, or 'any'
:param transport_protocol: str Transport protocol to use, or 'any'
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set tunnel openvpn",
options=f"-p {port} -t {transport_protocol}",
hide=hide,
**kwargs,
)
def mullvad_relay_set_tunnel_wireguard(
self,
port: str,
ip_version: str,
use_multihop: Literal["on", "off"],
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Set WireGuard-specific constraints
:param port: str Port to use, or 'any'
:param ip_version: str IP protocol to use, or 'any'
:param use_multihop: str Whether to enable multihop. The location constraints are specified with 'entry-location' [possible values: on, off]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set tunnel wireguard",
options=f"-p {port} -i {ip_version} -m {use_multihop}",
hide=hide,
**kwargs,
)
def mullvad_relay_set_tunnel_protocol(
self,
protocol: Literal["any", "wireguard", "openvpn"],
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Set tunnel protocol to use: 'any', 'wireguard', or 'openvpn'
:param protocol: str One of: 'any', 'wireguard', or 'openvpn'
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set tunnel-protocol",
options=protocol,
hide=hide,
**kwargs,
)
def mullvad_relay_set_custom_openvpn(
self,
host: str,
port: str,
username: str,
password: str,
transport_protocol: str = "UDP",
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Use a custom OpenVPN relay
:param host: str Hostname or IP
:param port: str Remote port
:param username: str Username for authentication
:param password: str Password for authentication
:param transport_protocol: str Transport protocol to use [default: UDP]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set custom openvpn",
options=" ".join([host, port, username, password, transport_protocol]),
hide=hide,
**kwargs,
)
def mullvad_relay_set_custom_wireguard(
self,
host: str,
port: str,
peer_pubkey: str,
tunnel_ip: list[str],
v4_gateway: str | None = None,
v6_gateway: str | None = None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Use a custom WireGuard relay
:param host: str Hostname or IP
:param port: str Remote port
:param peer_pubkey: str Base64 encoded public key of remote peer
:param tunnel_ip: list[str] IP addresses of local tunnel interface
:param v4_gateway: IPv4 gateway address
:param v6_gateway: IPv6 gateway address
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
f"mullvad relay set custom wireguard",
options=" ".join(
[
host,
port,
peer_pubkey,
*tunnel_ip,
f"--v4-gateway {v4_gateway}" if v4_gateway else "",
f"--v6-gateway {v6_gateway}" if v6_gateway else "",
]
),
hide=hide,
**kwargs,
)
def mullvad_relay_list(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
List available relays
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad relay list", hide=hide, **kwargs)
def mullvad_relay_update(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Update the relay list
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad relay update", hide=hide, **kwargs)
def mullvad_relay_override_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Show current custom fields for servers
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad relay override get", hide=hide, **kwargs)
def mullvad_relay_override_set_ipv4(
self, hostname: str, address: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Override entry IPv4 address for a given relay
:param hostname: str The unique hostname for the server to set the override on
:param address: str The IPv4 address to use to connect to this server
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad relay override set ipv4",
options=" ".join([hostname, address]),
hide=hide,
**kwargs,
)
def mullvad_relay_override_set_ipv6(
self, hostname: str, address: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Override entry IPv6 address for a given relay
:param hostname: str The unique hostname for the server to set the override on
:param address: str The IPv6 address to use to connect to this server
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad relay override set ipv6",
options=" ".join([hostname, address]),
hide=hide,
**kwargs,
)
def mullvad_relay_override_unset_ipv4(
self, hostname: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Remove overridden entry IPv4 address for the given server
:param hostname: str The unique hostname for the server to unset the override on
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad relay override unset ipv4", options=hostname, hide=hide, **kwargs
)
def mullvad_relay_override_unset_ipv6(
self, hostname: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Remove overridden entry IPv6 address for the given server
:param hostname: str The unique hostname for the server to unset the override on
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad relay override unset ipv6", options=hostname, hide=hide, **kwargs
)
def mullvad_relay_override_clear_all(
self, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Unset custom IPs for all servers
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad relay override clear-all", options="-y", hide=hide, **kwargs
)
def mullvad_api_access_get(self, hide: bool = True, **kwargs) -> invoke.Result:
"""
Display the current API access method
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run("mullvad api-access get", hide=hide, **kwargs)
def mullvad_api_access_add_socks5_remote(
self, name: str, remote_ip: str, remote_port: str, hide: bool = True, **kwargs
) -> invoke.Result:
"""
Configure a remote SOCKS5 proxy
:param name: str An easy to remember name for this custom proxy
:param remote_ip: str The IP of the remote proxy server
:param remote_port: str The port of the remote proxy server
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad api-access add socks5 remote",
options=" ".join([name, remote_ip, remote_port]),
hide=hide,
**kwargs,
)
def mullvad_api_access_add_socks5_local(
self,
name: str,
local_port: str,
remote_ip: str,
remote_port: str,
disabled: bool = False,
transport_protocol: Literal["TCP", "UDP"] = "TCP",
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Configure a remote SOCKS5 proxy
:param name: str An easy to remember name for this custom proxy
:param local_port: str The port that the server on localhost is listening on
:param remote_ip: str The IP of the remote peer
:param remote_port: str The port of the remote peer
:param disabled: bool Disable the use of this custom access method. It has to be manually enabled at a later stage to be used when accessing the Mullvad API
:param transport_protocol: str The Mullvad App can not know which transport protocol that the remote peer accepts, but it needs to know this in order to correctly exempt the connection traffic in the firewall.
By default, the transport protocol is assumed to be `TCP`, but it can optionally be set to `UDP` as well.
[default: TCP]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad api-access add socks5 local",
options=" ".join(
[
"-d" if disabled else "",
f"--transport-protocol {transport_protocol}",
name,
local_port,
remote_ip,
remote_port,
]
),
hide=hide,
**kwargs,
)
def mullvad_api_access_add_shadowsocks(
self,
name: str,
remote_ip: str,
remote_port: str,
password: str,
disabled: bool = False,
cipher: (
Literal[
"aes-128-cfb",
"aes-128-cfb1",
"aes-128-cfb8",
"aes-128-cfb128",
"aes-256-cfb",
"aes-256-cfb1",
"aes-256-cfb8",
"aes-256-cfb128",
"rc4",
"rc4-md5",
"chacha20",
"salsa20",
"chacha20-ietf",
"aes-128-gcm",
"aes-256-gcm",
"chacha20-ietf-poly1305",
"xchacha20-ietf-poly1305",
"aes-128-pmac-siv",
"aes-256-pmac-siv",
]
| None
) = None,
hide: bool = True,
**kwargs,
) -> invoke.Result:
"""
Configure a remote SOCKS5 proxy
:param name: str An easy to remember name for this custom proxy
:param remote_ip: str The IP of the remote Shadowsocks-proxy
:param remote_port: str Port on which the remote Shadowsocks-proxy listens for traffic
:param password: Password for authentication
:param disabled: bool Disable the use of this custom access method. It has to be manually enabled at a later stage to be used when accessing the Mullvad API
:param cipher: str Cipher to use [possible values: aes-128-cfb, aes-128-cfb1, aes-128-cfb8, aes-128-cfb128,
aes-256-cfb, aes-256-cfb1, aes-256-cfb8, aes-256-cfb128, rc4, rc4-md5, chacha20, salsa20, chacha20-ietf,
aes-128-gcm, aes-256-gcm, chacha20-ietf-poly1305, xchacha20-ietf-poly1305, aes-128-pmac-siv, aes-256-pmac-siv]
:param hide: One of "stdout" to hide stdout, "stderr" to hide stderr, True to hide both, or False to hide neither
:param kwargs: kwargs passed to invoke.Context.run()
:return: invoke.Result
"""
return self.run(
"mullvad api-access add shadowsocks",
options=" ".join(
[
"-d" if disabled else "",
f"--cipher {cipher}" if cipher else "",
name,
remote_ip,
remote_port,
password,
]
),
hide=hide,
**kwargs,
)