Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NordVPN version #4

Open
hartzan opened this issue Jul 12, 2020 · 6 comments
Open

NordVPN version #4

hartzan opened this issue Jul 12, 2020 · 6 comments

Comments

@hartzan
Copy link

hartzan commented Jul 12, 2020

Hi,

here https://gist.github.com/hartzan/b85644cb30799c98a449814c234f6953 you can find my version for NordVPN. Geoip stuff is not needed, NordVPN status message contains IP,country and city. Unfortunately there is no 2-letter country code so it might happen that all letters are not visible? I guess it's not perfect but works for me :-)

@shervinsahba
Copy link
Owner

Cool. I'm glad that the bulk of the script worked for Nord. Thanks for sharing hartzan!

Now time to think of a good way to merge these additions :)

@shervinsahba
Copy link
Owner

Could you paste the output of nordvpn status when it is disconnected and again when it's connected?

@hartzan
Copy link
Author

hartzan commented Jul 13, 2020

Here you are:

nordvpn status
Status: Disconnected

nordvpn status
Status: Connected
Current server: fi126.nordvpn.com
Country: Finland
City: Helsinki
Your new IP: 196.196.203.67
Current technology: NordLynx
Transfer: 42.00 KiB received, 26.96 KiB sent
Uptime: 9 seconds

@sudo-julia
Copy link
Contributor

sudo-julia commented Aug 1, 2020

I'm going to work on a small python program to:

  1. Take a country name as an argument
  2. Match and return it's county code with dictionaries

The script could then be called inside vpn_module.sh for quick conversion.
If it would be easier or quicker in bash let me know!

@shervinsahba
Copy link
Owner

@sudo-julia Sounds good! Yeah, that'd be clean. Seems like that would clean up about half the differences in code between Mullvad and Nord and set the script up for future services.

We have these basic utility differences, shown below, which I was thinking may be best kept in a setup file the user could run to swap out relevant pieces with sed commands. I imagine most users would be able to code them in manually, but it'd be nice to swap via a script. Do you think that makes sense?

## [Set VPN commands]. 

#MULLVAD
VPN_CONNECT="mullvad connect"
VPN_DISCONNECT="mullvad disconnect"
VPN_GET_STATUS="mullvad status"
VPN_SET_LOCATION="mullvad relay set location"

#NORD
VPN_CONNECT="nordvpn c"               # could use connect instead of c
VPN_DISCONNECT="nordvpn d"         # could use disconnect
VPN_GET_STATUS="nordvpn status"
VPN_SET_LOCATION="nordvpn c"      # this is the main one that differs


## [Set VPN status parsing]

#MULLVAD
VPN_STATUS="$($VPN_GET_STATUS | cut -d' ' -f3)"	
CONNECTED=Connected
CONNECTING=Connecting

#NORD
VPN_STATUS="$($VPN_GET_STATUS | sed -n 1p | cut -c 21-29)"	# could use cut -d' ' -f2. In either case, this differs.
CONNECTED=Connected
CONNECTING=                         # I'm unsure if Nord has a Connecting state

And then there is the regional information, which if I understand, your suggestion should let us manage much more efficiently.

#MULLVAD
COUNTRIES=("Albania (al)" "Australia (au)" "Austria (at)" "Belgium (be)" "Brazil (br)" "Bulgaria (bg)" "Canada (ca)" "Czech Republic (cz)" "Denmark (dk)" "Finland (fi)" "France (fr)" "Germany (de)" "Greece (gr)" "Hong Kong (hk)" "Hungary (hu)" "Ireland (ie)" "Israel (il)" "Italy (it)" "Japan (jp)" "Latvia (lv)" "Luxembourg (lu)" "Moldova (md)" "Netherlands (nl)" "New Zealand (nz)" "Norway (no)" "Poland (pl)" "Romania (ro)" "Serbia (rs)" "Singapore (sg)" "Spain (es)" "Sweden (se)" "Switzerland (ch)" "UK (gb)" "United Arab Emirates (ae)" "USA (us)")
COUNTRY_CODES=("al" "au" "at" "be" "br" "bg" "ca" "cz" "dk" "fi" "fr" "de" "gr" "hk" "hu" "ie" "il" "it" "jp" "lv" "lu" "md" "nl" "nz" "no" "pl" "ro" "rs" "sg" "es" "se" "ch" "gb" "ae" "us")

#NORD
COUNTRIES=("Albania" "Argentina" "Australia" "Austria" "Belgium" "Bosnia" "Brazil" "Bulgaria" "Canada" "Chile" "Costa Rica" "Croatia" "Cyprus" "Czech Republic" "Denmark" "Estonia" "Finland" "France" "Georgia" "Germany" "Greece" "Hong Kong" "Hungary" "Iceland" "India" "Indonesia" "Ireland" "Israel" "Italy" "Japan" "Latvia" "Luxembourg" "Macedonia" "Malaysia" "Mexico" "Moldova" "Netherlands" "New Zealand" "Norway" "Poland" "Portugal" "Romania" "Serbia" "Singapore" "Slovakia" "Slovenia" "South Africa" "South Korea" "Spain" "Sweden" "Switzerland" "Taiwan" "Thailand" "Turkey" "Ukraine" "United Arab Emirates" "United Kingdom" "United States" "Vietnam")


## Concatenate favorite and country arrays

#MULLVAD
VPN_CODES=("${VPN_LOCATIONS[@]}")
VPN_CODES+=("${COUNTRY_CODES[@]}")
VPN_LOCATIONS+=("${COUNTRIES[@]}")

#NORD
VPN_LOCATIONS+=("${COUNTRIES[@]}")
VPN_CODES=("${VPN_LOCATIONS[@]}")

Thanks!

@sudo-julia
Copy link
Contributor

Hey! Being able to swap variables with a script sounds like a really good idea. I think it's great to have options that are able to be configured without having to open the main script, which could be daunting for newer users even though the way you laid it out is super accessible.

If you check my fork the python script is up and running, I just got lost at where to integrate it in vpn_module.sh once I completed it (lmao). As of now, it takes a country name by arg, which is found with awk filtering a vpn status command (for portability), and returns the associated country code. Let me know exactly how that should be placed in the main script. I also might update it real quick to also return country name if country code is given but I'm not 100% sure if that would be useful. Let me know what you think and where it can be improved! Have a good one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants