-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathnordlist.sh
5424 lines (5423 loc) · 202 KB
/
nordlist.sh
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
#!/bin/bash
#
# Tested with NordVPN Version 3.19.2 on Linux Mint 21.3
# December 8, 2024
#
# This script works with the NordVPN Linux CLI. I started
# writing it to save some keystrokes on my Home Theatre PC.
# It keeps evolving and is still a work in progress. Bash
# scripting is new to me and I'm learning as I go. I added a
# lot of comments to help fellow newbies customize the script.
#
# Screenshots:
# https://github.com/ph202107/nordlist/tree/main/screenshots
#
# https://github.com/ph202107/nordlist
# Suggestions/feedback welcome
#
# =====================================================================
# Instructions
# =============
#
# 1) Save as nordlist.sh
# For convenience I use a directory in my PATH (echo $PATH)
# eg. /home/username/.local/bin/nordlist.sh
# 2) Make the script executable with
# "chmod +x nordlist.sh"
# 3) To generate ASCII images and to use NordVPN API functions
# these small programs are required
# eg. "sudo apt install figlet lolcat curl jq"
# 4) At the terminal run "nordlist.sh"
# (Or "./nordlist.sh" from the directory if it's not in $PATH)
#
# =====================================================================
# Other Programs Used
# ====================
#
# wireguard-tools Tools-WireGuard (function wireguard_gen)
# speedtest-cli Tools-Speed Tests (function speedtest_menu)
# iperf3 Meshnet-Speed Tests (function speedtest_iperf3)
# highlight Settings-Script (function script_info)
#
# "sudo apt install wireguard wireguard-tools speedtest-cli iperf3 highlight"
#
# For VPN On/Off status on the desktop I use the Linux Mint Cinnamon
# applet "Bash Sensors". Highly recommended for Cinnamon DE users.
# Screenshot: https://github.com/ph202107/nordlist/blob/main/screenshots
# When the status icon is clicked, it will launch this script in a new
# terminal. The config is in the "Notes" at the bottom of the script.
#
# =====================================================================
# Sudo Usage
# ===========
#
# These functions will ask for a sudo password:
# - function restart_service
# - function iptables_status
# - function iptables_flush
# - function wireguard_gen
# - function customdns_menu "Flush DNS Cache"
#
# =====================================================================
# Customization
# ==============
#
# Specify your P2P preferred location. (Optional)
# eg. p2pwhere="Canada" or p2pwhere="Toronto"
p2pwhere=""
#
# Specify your Obfuscated_Servers location. (Optional)
# The location must support obfuscation.
# eg. obwhere="United_States" or obwhere="Los_Angeles"
obwhere=""
#
# Specify the first hop to use for Double_VPN. (Optional)
# The location must have Double_VPN servers available.
# eg. dblwhere="United_Kingdom" or dblwhere="Sweden"
dblwhere=""
#
# Specify your Onion_Over_VPN location. (Optional)
# Typically Netherlands and Switzerland are available (~3 servers total)
# eg. torwhere="Netherlands" or torwhere="Switzerland"
torwhere=""
#
# Specify your Dedicated_IP location. (Optional)
# If you have a Dedicated IP you can specify your server, eg. "ca1692"
# Otherwise you can connect to the server group in a supported region.
# eg. dipwhere="Tokyo" or dipwhere="Johannesburg"
dipwhere=""
#
# Specify your Auto-Connect location. (Optional)
# eg. acwhere="Australia" or acwhere="Sydney"
# When obfuscate is enabled, the location must support obfuscation.
acwhere=""
#
# Specify your Custom-DNS servers with a description.
# Can specify up to 3 IP addresses separated by a space.
default_dns="103.86.96.100 103.86.99.100"; dnsdesc="Nord"
#
# Specify a VPN hostname to use for testing while the VPN is off.
# For example the VPN server configured on a local router.
# Can still enter any hostname later, this is just a default choice.
default_vpnhost="ca1576.nordvpn.com"
#
# Specify any hostname to lookup when testing DNS response time.
# Can also enter a different hostname later.
default_dnshost="reddit.com"
#
# Confirm the location of the NordVPN changelog on your system.
nordchangelog="/usr/share/doc/nordvpn/changelog.Debian.gz"
#
# Save incoming Meshnet file transfers into this folder.
# Note: $USER will automatically translate to your username.
# Use the absolute path, no trailing slash (/)
meshnetdir="/home/$USER/Downloads"
#
# Save generated WireGuard config files into this folder.
# Use the absolute path, no trailing slash (/)
wgdir="/home/$USER/Downloads"
#
# Specify the absolute path and filename to store a .json of all the
# NordVPN servers (about 20MB). Avoids API server timeouts. Create the
# list at: Tools - NordVPN API - All VPN Servers
nordserversfile="/home/$USER/Downloads/nord_allservers.json"
#
# Specify the absolute path and filename to store a local list of your
# favorite NordVPN servers. eg. Low ping servers or streaming servers.
# Create the list in: 'Favorites'
nordfavoritesfile="/home/$USER/Downloads/nord_favorites.txt"
#
# Specify the absolute path and filename to save a copy of the
# nordvpnd.service logs. Create the file in: Settings - Logs
nordlogfile="/home/$USER/Downloads/nord_logs.txt"
# Also show this number of lines from the tail of the log.
loglines="100"
#
# Change the terminal window titlebar text while the script is running.
# Leave this blank to keep the titlebar unchanged.
titlebartext="NORD"
#
# When changing servers disconnect the VPN first, then connect to the
# new server. "y" or "n"
disconnect="n"
#
# Always 'Rate Server' when disconnecting via the main menu. "y" or "n"
rate_prompt="y"
#
# Ask to pause the VPN when disconnecting via the main menu
# (disconnect and automatically reconnect). "y" or "n"
pause_prompt="y"
#
# Specify the default number of minutes to pause the VPN.
default_pause="5"
#
# Show the logo (ASCII and stats) when the script exits. "y" or "n"
exitlogo="y"
#
# Always enable the Kill Switch (and Firewall) when the script exits
# and the VPN is connected. "y" or "n"
exitkillswitch="n"
#
# Prompt to disable the Kill Switch when the script exits and
# the VPN is disconnected. "y" or "n"
exitks_prompt="y"
#
# Ping the connected server when the script exits. "y" or "n"
exitping="n"
#
# Query the current server load when the script exits. "y" or "n"
# Requires 'curl' 'jq' and the local 'nordserversfile' mentioned above.
exitload="n"
#
# Show your external IP address when the script exits. "y" or "n"
# Requires 'curl' and 'jq'. Connects to ipinfo.io.
exitip="n"
#
# Reload the "Bash Sensors" Cinnamon applet when the script exits.
# This will change the icon color (for connection status) immediately.
# Only for the Cinnamon DE with "Bash Sensors" installed. "y" or "n"
exitappletb="n"
#
# Reload the "Network Manager" Cinnamon applet when the script exits.
# This removes duplicate "nordlynx" entries from the applet. "y" or "n"
exitappletn="n"
#
# Open http links in a new Firefox window. "y" or "n"
# Choose "n" to use the default browser or method.
newfirefox="n"
#
# Specify the number of pings to send when pinging a destination.
pingcount="3"
#
# Set 'menuwidth' to your terminal width or lower. This will compact
# the menus horizontally. ("Countries" and "Favorites" excluded.)
# Leave blank to have the menu width change with the window size.
menuwidth="80"
#
# Choose the maximum number of characters for country names in the
# "Countries" menu. Shortens long names so the menu fits better in the
# terminal window. Minimum is "6". Leave blank to disable.
charlimit="12"
#
# Choosing 'Exit' in a submenu will take you to the main menu.
# Entering this value while in a submenu will return you to the default
# parent menu. Also works with most (y/n) prompts to exit the prompt.
# To avoid conflicts avoid using any number other than zero, or
# the letters y,n,c,e,s. eg. upmenu="0" or upmenu="b"
upmenu="0"
#
# =====================================================================
# Fast Options
# =============
#
# Fast options speed up the script by automatically answering 'yes'
# to prompts. Would recommend trying the script to see how it operates
# before enabling these options.
#
# Choose "y" or "n"
#
# Return to the main menu without prompting "Press any key..."
fast1="n"
#
# Automatically change these settings without prompting: Firewall,
# Routing, Analytics, KillSwitch, TPLite, Notify, Tray, AutoConnect,
# IPv6, LAN-Discovery, Virtual-Location, Post-Quantum
fast2="n"
#
# Automatically change these settings which also disconnect the VPN:
# Technology, Protocol, Obfuscate
fast3="n"
#
# Automatically disconnect, change settings, and connect to these
# groups: Obfuscated, Double-VPN, Onion+VPN, P2P, Dedicated-IP
fast4="n"
#
# Always enable the Kill Switch (& Firewall) when connecting to groups.
# (Does not apply when connecting through the "All_Groups" menu.)
fast5="n"
#
# Always choose the same protocol when asked to choose TCP or UDP.
# (Unless changing the setting through Settings - Protocol.)
fast6="n" # "y" or "n"
fast6p="UDP" # specify the protocol. fast6p="UDP" or fast6p="TCP"
#
# When choosing a country from the 'Countries' menu, immediately
# connect to that country instead of choosing a city.
fast7="n"
#
# By default the 'F' indicator will be set when any of the 'fast'
# options are enabled.
# Modify 'allfast' if you want to display the 'F' indicator only when
# specific 'fast' options are enabled.
allfast=("$fast1" "$fast2" "$fast3" "$fast4" "$fast5" "$fast6" "$fast7")
#
# =====================================================================
# Virtual Servers
# ================
#
# Countries and Cities listed here will be labelled as (Virtual).
# Refer to: https://nordvpn.com/blog/new-nordvpn-virtual-servers/
# This list is subject to change and must be updated manually.
# Retrieve an updated list in "Tools - NordVPN API - All VPN Servers"
nordvirtual=(
"Accra" "Algeria" "Algiers" "Andorra" "Andorra_la_Vella" "Angola" "Argentina" "Armenia" "Astana" "Asuncion" "Azerbaijan" "Bahamas" "Baku" "Bandar_Seri_Begawan" "Bangkok" "Bangladesh" "Beirut" "Belize" "Belmopan" "Bermuda" "Bhutan" "Bolivia" "Brunei_Darussalam" "Buenos_Aires" "Cairo" "Cambodia" "Caracas" "Cayman_Islands" "Colombo" "Costa_Rica" "Dhaka" "Dominican_Republic" "Douglas" "Ecuador" "Egypt" "El_Salvador" "George_Town" "Ghana" "Greenland" "Guam" "Guatemala" "Guatemala_City" "Hagatna" "Hamilton" "Hanoi" "Ho_Chi_Minh_City" "Honduras" "India" "Isle_of_Man" "Jamaica" "Jersey" "Karachi" "Kathmandu" "Kazakhstan" "Kenya" "Kingston" "Lao_People's_Democratic_Republic" "La_Paz" "Lebanon" "Liechtenstein" "Luanda" "Malta" "Manila" "Maputo" "Monaco" "Mongolia" "Monte_Carlo" "Montenegro" "Montevideo" "Morocco" "Mozambique" "Mumbai" "Myanmar" "Nairobi" "Nassau" "Naypyidaw" "Nepal" "Nuuk" "Pakistan" "Panama" "Panama_City" "Papua_New_Guinea" "Paraguay" "Philippines" "Phnom_Penh" "Podgorica" "Port_Moresby" "Port_of_Spain" "Puerto_Rico" "Quito" "Rabat" "Saint_Helier" "San_Jose" "San_Juan" "San_Salvador" "Santo_Domingo" "Sri_Lanka" "Taipei" "Taiwan" "Tashkent" "Tegucigalpa" "Thailand" "Thimphu" "Trinidad_and_Tobago" "Ulaanbaatar" "Uruguay" "Uzbekistan" "Vaduz" "Valletta" "Venezuela" "Vientiane" "Vietnam" "Yerevan"
)
#
# =====================================================================
# Visual Options
# ===============
#
# Change the main menu figlet ASCII style in "function ascii_custom"
# Change the figlet ASCII style for headings in "function heading"
# Change the text and indicator colors in "function set_colors"
# Change the indicator layout in "function indicators_display"
#
# =====================================================================
# Allowlist & Default Settings
# =============================
#
# Add your allowlist commands to "function allowlist_commands"
# Set up a default NordVPN config in "function set_defaults"
#
# =====================================================================
# Main Menu
# ==========
#
# The Main Menu starts on line 400 (function main_menu).
# Configure the first ten main menu items to suit your needs.
#
# Enjoy!
#
# ==End================================================================
#
declare -A nordlist_apps # populated in function app_exists
#
function allowlist_commands {
# Add your allowlist configuration commands here.
# Enter one command per line.
# allowlist_start (keep this line as-is)
#
#nordvpn allowlist remove all
#nordvpn allowlist add subnet 192.168.1.0/24
#
# allowlist_end (keep this line as-is)
echo
}
function set_defaults {
echo
echo -e "${LColor}Apply the default configuration.${Color_Off}"
echo
# Calling this function can be useful to change multiple settings
# at once and get back to a typical configuration.
#
# Configure as needed and comment-out the line below.
echo -e "${WColor}** 'function set_defaults' not configured **${Color_Off}"; echo; return
#
# Notes:
# - The VPN will be disconnected
# - Kill Switch requires Firewall
# - NordLynx is UDP only
# - Obfuscate requires OpenVPN
# - TPLite disables CustomDNS and vice versa
# - LAN-Discovery will remove private subnets from Allowlist
# - Post Quantum VPN requires NordLynx, and Meshnet disabled
#
# For each setting uncomment one of the two choices (or neither).
#
if [[ "$firewall" == "disabled" ]]; then nordvpn set firewall enabled; fi
#if [[ "$firewall" == "enabled" ]]; then nordvpn set firewall disabled; fi
#
if [[ "$killswitch" == "disabled" ]]; then nordvpn set killswitch enabled; fi
#if [[ "$killswitch" == "enabled" ]]; then nordvpn set killswitch disabled; fi
#
disconnect_vpn "force"
#
if [[ "$technology" == "openvpn" ]]; then if [[ "$protocol" == "TCP" ]]; then nordvpn set protocol UDP; fi; nordvpn set technology nordlynx; set_vars; fi
#if [[ "$technology" == "nordlynx" ]]; then if [[ "$postquantum" == "enabled" ]]; then nordvpn set post-quantum disabled; fi; nordvpn set technology openvpn; set_vars; fi
#
if [[ "$protocol" == "TCP" ]]; then nordvpn set protocol UDP; fi
#if [[ "$protocol" == "UDP" ]]; then nordvpn set protocol TCP; fi
#
if [[ "$routing" == "disabled" ]]; then nordvpn set routing enabled; fi
#if [[ "$routing" == "enabled" ]]; then nordvpn set routing disabled; fi
#
#if [[ "$analytics" == "disabled" ]]; then nordvpn set analytics enabled; fi
#if [[ "$analytics" == "enabled" ]]; then nordvpn set analytics disabled; fi
#
#if [[ "$tplite" == "disabled" ]]; then nordvpn set threatprotectionlite enabled; fi
if [[ "$tplite" == "enabled" ]]; then nordvpn set threatprotectionlite disabled; fi
#
#if [[ "$obfuscate" == "disabled" ]]; then nordvpn set obfuscate enabled; fi
if [[ "$obfuscate" == "enabled" ]]; then nordvpn set obfuscate disabled; fi
#
#if [[ "$notify" == "disabled" ]]; then nordvpn set notify enabled; fi
if [[ "$notify" == "enabled" ]]; then nordvpn set notify disabled; fi
#
#if [[ "$tray" == "disabled" ]]; then nordvpn set tray enabled; fi
#if [[ "$tray" == "enabled" ]]; then nordvpn set tray disabled; fi
#
#if [[ "$autoconnect" == "disabled" ]]; then nordvpn set autoconnect enabled $acwhere; fi
if [[ "$autoconnect" == "enabled" ]]; then nordvpn set autoconnect disabled; fi
#
#if [[ "$ipversion6" == "disabled" ]]; then nordvpn set ipv6 enabled; fi
if [[ "$ipversion6" == "enabled" ]]; then nordvpn set ipv6 disabled; fi
#
#if [[ "$meshnet" == "disabled" ]]; then nordvpn set meshnet enabled; fi
#if [[ "$meshnet" == "enabled" ]]; then nordvpn set meshnet disabled; fi
#
#if [[ "$customdns" == "disabled" ]]; then nordvpn set dns $default_dns; fi
#if [[ "$customdns" != "disabled" ]]; then nordvpn set dns disabled; fi
#
#if [[ "$landiscovery" == "disabled" ]]; then nordvpn set lan-discovery enabled; fi
#if [[ "$landiscovery" == "enabled" ]]; then nordvpn set lan-discovery disabled; fi
#
#if [[ "$virtual" == "disabled" ]]; then nordvpn set virtual-location enabled; fi
#if [[ "$virtual" == "enabled" ]]; then nordvpn set virtual-location disabled; fi
#
#if [[ "$postquantum" == "disabled" ]]; then nordvpn set post-quantum enabled; fi
#if [[ "$postquantum" == "enabled" ]]; then nordvpn set post-quantum disabled; fi
#
echo
}
function main_menu {
if [[ "$1" == "start" ]]; then
echo -e "${EIColor}Welcome to nordlist!${Color_Off}"
elif [[ "$fast1" =~ ^[Yy]$ ]] || [[ "$REPLY" == "$upmenu" ]]; then
echo
else
echo; echo
read -n 1 -s -r -p "Press any key for the menu... "; echo
fi
echo
#
clear -x
main_logo
parent="Main"
COLUMNS="$menuwidth"
PS3=$'\n''Choose an option: '
#
# =================================================================
# ====== MAIN MENU ================================================
# =================================================================
#
# To modify the menu, for example changing Vancouver to Melbourne:
# - In the (Menu Array) below
# replace "Vancouver" with "Melbourne"
# - In the (Case Statement) below
# also replace "Vancouver" with "Melbourne"
# and replace: "nordvpn connect Vancouver"
# with: "nordvpn connect Melbourne"
# No other changes are necessary.
#
# Each option in the Menu Array should have a matching case.
# Spelling and capitalization must match exactly in both places.
#
# An almost unlimited number of menu items can be added.
# Submenu functions can be added to the main menu for easier access.
#
# ===== (Menu Array) =====
# These are the options that will be displayed on the main menu.
mainmenu=( "Vancouver" "Seattle" "Chicago" "Denver" "Atlanta" "US_Cities" "CA_Cities" "P2P-USA" "P2P-Canada" "Discord" "QuickConnect" "Random" "Favorites" "Countries" "Groups" "Settings" "Tools" "Meshnet" "Disconnect" "Exit" )
#
select opt in "${mainmenu[@]}"
do
parent_menu
case $opt in
#
# ===== (Case Statement) =====
# These are the commands that run when a menu option is selected.
#
"Vancouver")
main_header
nordvpn connect Vancouver
status
break
;;
"Seattle")
main_header
nordvpn connect Seattle
status
break
;;
"Chicago")
main_header
nordvpn connect Chicago
status
break
;;
"Denver")
main_header
nordvpn connect Denver
status
break
;;
"Atlanta")
main_header
nordvpn connect Atlanta
status
break
;;
"US_Cities")
# city menu for United_States
xcountry="United_States"
city_menu "Main"
;;
"CA_Cities")
# city menu for Canada
xcountry="Canada"
city_menu "Main"
;;
"P2P-USA")
# force a disconnect and apply default settings
main_header "defaults"
nordvpn connect --group p2p United_States
status
break
;;
"P2P-Canada")
# force a disconnect and apply default settings
main_header "defaults"
nordvpn connect --group p2p Canada
status
break
;;
"Discord")
# I use this entry to connect to a specific server which can help
# avoid repeat authentication requests. It then opens a URL.
# It may be useful for other sites or applications.
# Example: NordVPN discord https://discord.gg/83jsvGqpGk
#
spec_server="us8247"
spec_url="https://discord.gg/83jsvGqpGk"
#
main_header
echo -e "Server: ${LColor}$spec_server${Color_Off}"
echo -e "URL: ${EColor}$spec_url${Color_Off}"
echo
nordvpn connect "$spec_server"
status
openlink "$spec_url"
break
;;
"Hostname")
# can add to mainmenu
# connect to specific servers by name
host_connect
;;
"QuickConnect")
# alternative to "nordvpn connect"
quick_connect
;;
"Random")
# connect to a random city worldwide
random_worldwide
;;
"Favorites")
# connect from a list of individual server names
favorites_menu
;;
"Countries")
country_menu
;;
"Groups")
group_menu
;;
"Settings")
settings_menu
;;
"Tools")
tools_menu
;;
"Meshnet")
meshnet_menu
;;
"Disconnect")
main_disconnect
;;
"Exit")
heading "Goodbye!"
status
break
;;
*)
invalid_option "${#mainmenu[@]}" "TopMenu"
main_menu
;;
esac
done
exit
}
function ascii_static {
# This ASCII will display above the main menu if figlet or lolcat is not installed.
# You can also use your own ASCII art and specify "ascii_static" in "function main_logo".
# Change the color in "function set_colors".
echo -ne "${ASColor}"
#
cat << "EOF"
_ _ ___ ______ _ _
| \ | | ___ _ __ __| \ \ / / _ \| \ | |
| \| |/ _ \| '__/ _' |\ \ / /| |_) | \| |
| |\ | (_) | | | (_| | \ V / | __/| |\ |
|_| \_|\___/|_| \__,_| \_/ |_| |_| \_|
EOF
#
echo -ne "${Color_Off}"
}
function ascii_custom {
if ! app_exists "figlet" || ! app_exists "lolcat"; then
ascii_static
return
fi
# This ASCII is displayed above the main menu. Any text or variable(s) can be used.
# eg. "$city", "$country", "$transferd", "NordVPN", "$HOSTNAME", "$(date)", etc.
#
asciitext="$city"
#
if "$meshrouting"; then
# when routing through meshnet
asciitext="Meshnet Routing"
fi
if [[ "$connected" == "connected" ]]; then
# Add or remove any figlet fonts, arrange from largest to smallest or by preference.
for figletfont in slant standard smslant small none
do
if [[ "$figletfont" == "none" ]]; then
# If no ascii fonts will fit then print regular text.
echo
echo "====== ${asciitext^^} ======" | lolcat -p 0.7
#echo -e "${H1Color}====== ${asciitext^^} ======${Color_Off}"
echo
elif (( "$(tput cols)" > "$(wc -L <<< "$(figlet -w 999 -f "$figletfont" "$asciitext")")" )); then
# Check the current terminal width, and the width required for the ascii font.
figlet -t -f "$figletfont" "$asciitext" | lolcat
break
fi
done
else
# style when disconnected
figlet -t -f "standard" "NordVPN"
fi
}
function indicators_display {
# The "nordvpn settings" enabled/disabled indicators shown on the main menu, settings menu, and group connect.
# $1 = "group" - group menu indicators
#
# Use any symbol to separate the indicators. Set a color in function set_colors.
#indsep=" " # blank space
#indsep="\u2758" # unicode vertical line
indsep="\u00B7" # unicode middle-dot
#
if [[ "$1" == "group" ]]; then
echo -n "Current settings: "
indall=( "$techpro" "$fw" "$ks" "$ob" "$pq" )
else
indall=( "$techpro" "$fw" "$rt" "$an" "$ks" "$tp" "$ob" "$no" "$tr" "$ac" "$ip6" "$mn" "$dns" "$ld" "$vl" "$pq" "$al" )
if [[ -n "$fst" ]]; then indall+=( "$fst" ); fi
if [[ -n "$sshi" ]]; then indall+=( "$sshi" ); fi
fi
# array index (starts at zero)
for idx in "${!indall[@]}"; do
echo -ne "${indall[idx]}"
if (( (idx + 1) < "${#indall[@]}" )); then
echo -ne "${ISColor}$indsep${Color_Off}"
fi
done
echo
}
function main_logo {
# The ascii and stats shown above the main_menu and on script exit.
set_vars
if [[ "$1" != "stats_only" ]]; then
# Specify ascii_static or ascii_custom on the line below.
ascii_custom
fi
if "$meshrouting"; then
echo -e "$connectedcl ${SVColor}$nordhost ${IPColor}$ipaddr${Color_Off}"
else
echo -e "$connectedcl ${CIColor}$city ${COColor}$country ${SVColor}$server ${IPColor}$ipaddr ${Color_Off}$fav"
fi
indicators_display
echo -e "$transferc ${UPColor}$uptime${Color_Off}"
if [[ -n "$transferc" ]]; then echo; fi
}
function heading {
# The text or ASCII that displays after a menu selection is made.
# $1 = heading text
# $2 = "txt" - use regular text instead of figlet
# $3 = "alt" - use alternate color for regular text
#
clear -x
if ! app_exists "figlet" || ! app_exists "lolcat" || [[ "$2" == "txt" ]]; then
echo
if [[ "$3" == "alt" ]]; then
echo -e "${H2Color}=== $1 ===${Color_Off}"
else
echo -e "${H1Color}=== $1 ===${Color_Off}"
fi
echo
else
# Add or remove any figlet fonts, arrange from largest to smallest or by preference.
for figletfont in slant standard smslant small none
do
if [[ "$figletfont" == "none" ]]; then
# If no ascii fonts will fit then print regular text.
echo
echo -e "${H1Color}=== $1 ===${Color_Off}"
echo
elif (( "$(tput cols)" > "$(wc -L <<< "$(figlet -w 999 -f "$figletfont" "$1")")" )); then
# Check the current terminal width, and the width required for the ascii font.
figlet -t -f "$figletfont" "$1" | lolcat -p 1000
break
fi
done
fi
if [[ "$1" == "Countries" ]] || [[ "$1" == "Favorites" ]]; then
return
else
COLUMNS="$menuwidth"
fi
}
function set_colors {
#
# shellcheck disable=SC2034
# supress warning about unused color variables
{
# Regular
Black='\033[0;30m'
Red='\033[0;31m'
Green='\033[0;32m'
Yellow='\033[0;33m'
Blue='\033[0;34m'
Purple='\033[0;35m'
Cyan='\033[0;36m'
White='\033[0;97m'
#
# Light
LGrey='\033[0;37m'
DGrey='\033[0;90m' # Dark
LRed='\033[0;91m'
LGreen='\033[0;92m'
LYellow='\033[0;93m'
LBlue='\033[0;94m'
LPurple='\033[0;95m'
LCyan='\033[0;96m'
#
# Bold
BBlack='\033[1;30m'
BRed='\033[1;31m'
BGreen='\033[1;32m'
BYellow='\033[1;33m'
BBlue='\033[1;34m'
BPurple='\033[1;35m'
BCyan='\033[1;36m'
BWhite='\033[1;37m'
#
# Underline
UBlack='\033[4;30m'
URed='\033[4;31m'
UGreen='\033[4;32m'
UYellow='\033[4;33m'
UBlue='\033[4;34m'
UPurple='\033[4;35m'
UCyan='\033[4;36m'
UWhite='\033[4;37m'
#
# Background
# eg: ${White}${On_Red} = White text on red background
On_Black='\033[40m'
On_Red='\033[41m'
On_Green='\033[42m'
On_Yellow='\033[43m'
On_Blue='\033[44m'
On_Purple='\033[45m'
On_Cyan='\033[46m'
On_White='\033[47m'
#
Color_Off='\033[0m'
}
#
# ============== Change colors here if needed. ====================
#
EColor=${LGreen} # Enabled text
EIColor=${BGreen} # Enabled indicator
DColor=${LRed} # Disabled text
DIColor=${BRed} # Disabled indicator
FColor=${LYellow} # Fast text
FIColor=${BYellow} # Fast indicator
TColor=${BPurple} # Technology and Protocol text
TIColor=${BPurple} # Technology and Protocol indicator
#
WColor=${BRed} # Warnings, errors, disconnects
LColor=${LCyan} # 'Changes' lists and key info text
ASColor=${BBlue} # Color for the ascii_static image
H1Color=${LGreen} # Non-figlet headings
H2Color=${LCyan} # Non-figlet headings alternate
# main_logo
CNColor=${LGreen} # Connected status
DNColor=${LRed} # Disconnected status
CIColor=${Color_Off} # City name
COColor=${Color_Off} # Country name
SVColor=${Color_Off} # Server name
IPColor=${Color_Off} # IP address
FVColor=${LCyan} # Favorite|Dedicated-IP|Virtual label
ISColor=${DGrey} # Indicators separator
DLColor=${Green} # Download stat
ULColor=${Yellow} # Upload stat
UPColor=${Cyan} # Uptime stat
#
}
#
# =====================================================================
# =====================================================================
#
function nstatus_search {
# search the nstatus array by line
# $1 = search string
# $2 = "line" - return the entire line
#
if [[ "$2" == "line" ]]; then
printf '%s\n' "${nstatus[@]}" | grep -i "$1"
else
# the last field using <colon><space> as delimiter
# some elements may have spaces eg Los Angeles, United States
printf '%s\n' "${nstatus[@]}" | grep -i "$1" | awk -F': ' '{print $NF}'
fi
}
function nsettings_search {
# search the nsettings array by line
# $1 = search string
# $2 = "line" - return the entire line
#
if [[ "$2" == "line" ]]; then
printf '%s\n' "${nsettings[@]}" | grep -i "$1"
else
# the last field using <space> as delimiter
printf '%s\n' "${nsettings[@]}" | grep -i "$1" | awk -F' ' '{print $NF}'
fi
}
function set_vars {
# Store info in arrays (BASH v4)
readarray -t nstatus < <( nordvpn status | tr -d '\r' )
readarray -t nsettings < <( nordvpn settings | tr -d '\r' | tr '[:upper:]' '[:lower:]' )
#
# "nordvpn status"
# When disconnected, $connected is the only variable from nstatus
# When meshnet is enabled, the transfer stats will not be zeroed on VPN reconnect.
connected=$( nstatus_search "Status" | tr '[:upper:]' '[:lower:]' )
servername=$( nstatus_search "Server" )
nordhost=$( nstatus_search "Hostname" )
server=$( echo "$nordhost" | cut -f1 -d'.' )
ipaddr=$( nstatus_search "IP:" )
country=$( nstatus_search "Country" )
city=$( nstatus_search "City" )
protocol2=$( nstatus_search "protocol" | tr '[:lower:]' '[:upper:]' )
transferd=$( nstatus_search "Transfer" "line" | cut -f 2-3 -d' ' ) # download stat with units
transferu=$( nstatus_search "Transfer" "line" | cut -f 5-6 -d' ' ) # upload stat with units
uptime=$( nstatus_search "Uptime" "line" | cut -f 1-9 -d' ' )
#
# "nordvpn settings"
# $protocol and $obfuscate are not listed when using NordLynx
# $postquantum is not listed when using OpenVPN
technology=$( nsettings_search "Technology" )
protocol=$( nsettings_search "Protocol" | tr '[:lower:]' '[:upper:]' )
firewall=$( nsettings_search "Firewall:" )
fwmark=$( nsettings_search "Firewall Mark" )
routing=$( nsettings_search "Routing" )
analytics=$( nsettings_search "Analytics" )
killswitch=$( nsettings_search "Kill" )
tplite=$( nsettings_search "Threat" )
obfuscate=$( nsettings_search "Obfuscate" )
notify=$( nsettings_search "Notify" )
tray=$( nsettings_search "Tray" )
autoconnect=$( nsettings_search "Auto" )
ipversion6=$( nsettings_search "IPv6" )
meshnet=$( nsettings_search "Meshnet" | tr -d '\n' )
customdns=$( nsettings_search "DNS" ) # disabled or not=disabled
dns_servers=$( nsettings_search "DNS" "line" | tr '[:lower:]' '[:upper:]' ) # Server IPs, includes "DNS: "
landiscovery=$( nsettings_search "Discover" )
virtual=$( nsettings_search "Virtual" )
postquantum=$( nsettings_search "quantum" )
allowlist=$( printf '%s\n' "${nsettings[@]}" | grep -A100 -i "allowlist" )
#
# Prefer common spelling.
if [[ "$technology" == "openvpn" ]]; then technologyd="OpenVPN"
elif [[ "$technology" == "nordlynx" ]]; then technologyd="NordLynx"
fi
technologydc="${TColor}$technologyd${Color_Off}"
#
# To display the protocol for either Technology whether connected or disconnected.
if [[ "$connected" == "connected" ]]; then protocold="$protocol2"
elif [[ "$technology" == "nordlynx" ]]; then protocold="UDP"
else protocold="$protocol"
fi
protocoldc="${TColor}$protocold${Color_Off}"
#
techpro="${TIColor}$technologyd\u00B7$protocold${Color_Off}"
#
if [[ "$connected" == "connected" ]]; then
connectedc="${CNColor}$connected${Color_Off}"
connectedcl="${CNColor}${connected^}${Color_Off}:"
transferc="${DLColor}\u25bc $transferd ${ULColor} \u25b2 $transferu ${Color_Off}"
else
connectedc="${DNColor}$connected${Color_Off}"
connectedcl="${DNColor}${connected^}${Color_Off}"
transferc=""
fi
#
if [[ "$firewall" == "enabled" ]]; then
fw="${EIColor}FW${Color_Off}"
firewallc="${EColor}$firewall${Color_Off}"
else
fw="${DIColor}FW${Color_Off}"
firewallc="${DColor}$firewall${Color_Off}"
fi
#
if [[ "$routing" == "enabled" ]]; then
rt="${EIColor}RT${Color_Off}"
routingc="${EColor}$routing${Color_Off}"
else
rt="${DIColor}RT${Color_Off}"
routingc="${DColor}$routing${Color_Off}"
fi
#
if [[ "$analytics" == "enabled" ]]; then
an="${EIColor}AN${Color_Off}"
else
an="${DIColor}AN${Color_Off}"
fi
#
if [[ "$killswitch" == "enabled" ]]; then
ks="${EIColor}KS${Color_Off}"
killswitchc="${EColor}$killswitch${Color_Off}"
else
ks="${DIColor}KS${Color_Off}"
killswitchc="${DColor}$killswitch${Color_Off}"
fi
#
if [[ "$tplite" == "enabled" ]]; then
tp="${EIColor}TP${Color_Off}"
else
tp="${DIColor}TP${Color_Off}"
fi
#
if [[ "$obfuscate" == "enabled" ]]; then
ob="${EIColor}OB${Color_Off}"
obfuscatec="${EColor}$obfuscate${Color_Off}"
else
ob="${DIColor}OB${Color_Off}"
obfuscatec="${DColor}$obfuscate${Color_Off}"
fi
#
if [[ "$notify" == "enabled" ]]; then
no="${EIColor}NO${Color_Off}"
else
no="${DIColor}NO${Color_Off}"
fi
#
if [[ "$tray" == "enabled" ]]; then
tr="${EIColor}TR${Color_Off}"
else
tr="${DIColor}TR${Color_Off}"
fi
#
if [[ "$autoconnect" == "enabled" ]]; then
ac="${EIColor}AC${Color_Off}"
else
ac="${DIColor}AC${Color_Off}"
fi
#
if [[ "$ipversion6" == "enabled" ]]; then
ip6="${EIColor}IP6${Color_Off}"
else
ip6="${DIColor}IP6${Color_Off}"
fi
#
if [[ "$meshnet" == "enabled" ]]; then
mn="${EIColor}MN${Color_Off}"
meshnetc="${EColor}$meshnet${Color_Off}"
else
mn="${DIColor}MN${Color_Off}"
meshnetc="${DColor}$meshnet${Color_Off}"
fi
#
if [[ "$customdns" == "disabled" ]]; then # reversed
dns="${DIColor}DNS${Color_Off}"
else
dns="${EIColor}DNS${Color_Off}"
fi
#
if [[ "$landiscovery" == "enabled" ]]; then
ld="${EIColor}LD${Color_Off}"
landiscoveryc="${EColor}$landiscovery${Color_Off}"
else
ld="${DIColor}LD${Color_Off}"
landiscoveryc="${DColor}$landiscovery${Color_Off}"
fi
#
if [[ "$virtual" == "enabled" ]]; then
vl="${EIColor}VL${Color_Off}"
virtualc="${EColor}$virtual${Color_Off}"
else
vl="${DIColor}VL${Color_Off}"
virtualc="${DColor}$virtual${Color_Off}"
fi
#
if [[ "$postquantum" == "enabled" ]]; then
pq="${EIColor}PQ${Color_Off}"
postquantumc="${EColor}$postquantum${Color_Off}"
else
pq="${DIColor}PQ${Color_Off}"
# $postquantum not listed when using openvpn
postquantumc="${DColor}disabled${Color_Off}"
fi
#
if [[ -n "${allowlist[*]}" ]]; then # not empty
al="${EIColor}AL${Color_Off}"
else
al="${DIColor}AL${Color_Off}"
fi
#
if [[ ${allfast[*]} =~ [Yy] ]]; then
fst="${FIColor}F${Color_Off}"
else
fst=""
fi
#
if "$usingssh"; then
sshi="${FIColor}SSH${Color_Off}"
else
sshi=""
fi
#
if [[ "$connected" == "connected" ]] && [[ "$meshnet" == "enabled" ]] && [[ "$nordhost" != *"nordvpn.com"* ]]; then
meshrouting="true"
else
meshrouting="false"
fi
#
if [[ "$connected" == "connected" ]] && [[ "$technology" == "openvpn" ]] && [[ "${server,,}" == "${dipwhere,,}" ]]; then
fav="${FVColor}(Dedicated-IP)${Color_Off}"