-
Notifications
You must be signed in to change notification settings - Fork 42
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
Won't generate a config for anything other than the local "recommended" server #2
Comments
@freefly42 If you specify the country it gives you back the best server for that country. If you just specify the city, it gives you the best server for that city. You are right, I don't think they work together at the moment. I'd love your contribution. |
I can't give you a pull request as I don't use your code, and haven't forked it. I use a significantly different approach as I've found the private key and IP don't change, so I can really quickly get a server from just the API using stored private data. If the connection doesn't work, I regenerate the private data. However, my script for getting the private data will get exactly the information you want from your nordvpn connection. I will share both scripts here for your edification: nordregen.sh Any arguments passed to this script I pass to the nordvpn connection, so I can specify a country or other options if desired. It collects the private data and stores it in a form that's designed to source as a shell script (so no further parsing is required):
Since the connections to nord vpn take some time, I have a different script for quickly generating a config based on the API nordgen.sh:
So you could either add a filter to the curl call to get a server in the country you're interested in: |
@freefly42 Thank you! I will take a look as soon as I have a change and sure use your code for improvements. Let's leave this open so I don't forget to get to it. Thank you again, Stefano |
Ok I decided to pare it down to a single script for you. This would do what you want, supply the arguments to the script to specify options to nordvpn to specify country server type etc. So to get a connection for Germany just do:
|
While you connect to the specified country when you run the nordvpn c $COUNTRY $CITY to get the private key and local address information, the API call you make using curl where you get the hostname and public key for the server doesn't specify the specific server you connected to in the proper country. So you should either edit your curl call to specify the same server as you connect to with nordvpn, or modify the curl call to get the server info (adding the country/city specification to the API call) and then connect to that host with nordvpn to get the private key and IP information. Or you could do something like this while connected to get the endpoint name and public key (leaving no reason to make the API call in curl):
For client connections I would recommend removing the PersistentKeepAlive option as you only need it if you want the server to be able to arbitrarily reach you, or hosts on the server side to be able to reach you. It defeats the "keep quiet unless needed" security benefit of wireguard.
You could also make your script much easier to follow (and in the event of an error less likely to overwrite a good configuration file with a partially generated configuration file) by doing something like this at the end to write the file:
The text was updated successfully, but these errors were encountered: