phirecc / wgnord

A NordVPN Wireguard ("NordLynx") client in POSIX shell
MIT License
20 stars 5 forks source link

Allow connecting to specific server by hostname #10

Closed phirecc closed 2 months ago

phirecc commented 2 months ago

Addresses #5. Alternative solution to #9.

hostname_ids.txt generated via:

curl -G 'https://api.nordvpn.com/v1/servers' --data-urlencode 'limit=9999999' | jq -r '.[] | .hostname + "|" + (.id|tostring)'

It would make sense to periodically re-generate this file via a Github workflow.

I would've liked to use a filter like filters[servers.hostname], but that doesn't seem to work. NordVPN uses this approach with the server id themselves https://github.com/NordSecurity/nordvpn-linux/blob/main/core/core.go#L391

Please comment if this works for you @marvin1099 @Bundy01 I don't have a NordVPN account to test this with right now.

Bundy01 commented 2 months ago

Hi, thanks for the effort.

Unfortunately it doesn't work for me.

wgnord c de507
grep: hostname_ids.txt: No files or folders with this name
No server with hostname matching de507 found

In the hostname_ids.txt file, de507.nordvpn.com should be replaced by de507.

But despite the full name, I'm connecting to the server nearest to me (same country of residence) without any errors :(

marvin1099 commented 2 months ago

Hi, thanks for the effort.

Unfortunately it doesn't work for me.

wgnord c de507
grep: hostname_ids.txt: No files or folders with this name
No server with hostname matching de507 found

In the hostname_ids.txt file, de507.nordvpn.com should be replaced by de507.

But despite the full name, I'm connecting to the server nearest to me (same country of residence) without any errors :(

This was not jet added to the script, its still under review or we are also thinking about a other way of implementing it. If you want to try is you can use the new idea here. But we probably figure something ot soon.

Edit: My mistake I think I missread. You can try it out here, you referred phirecc's solution that I have no idea about.

Bundy01 commented 2 months ago

@marvin1099

your modification doesn't work either.

wgnord c de509
Finding best server...
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq

and wgnord c ro also connects me to a server in my country.

marvin1099 commented 2 months ago

Interesting idea using a static list but since some severs might change a API pull might be better, just my thoughts, I mean that's what I have and a solution that is best here is not jet decided on.

marvin1099 commented 2 months ago

@marvin1099

your modification doesn't work either.

wgnord c de509
Finding best server...
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq
jq: invalid JSON text passed to --argjson
Use jq --help for help with command-line options,
or see the jq manpage, or online docs at https://jqlang.github.io/jq

and wgnord c ro also connects me to a server in my country.

Have to look ito that, I wanted to make a bit more simplified anyway

phirecc commented 2 months ago

Hi, thanks for the effort.

Unfortunately it doesn't work for me.

wgnord c de507
grep: hostname_ids.txt: No files or folders with this name
No server with hostname matching de507 found

In the hostname_ids.txt file, de507.nordvpn.com should be replaced by de507.

But despite the full name, I'm connecting to the server nearest to me (same country of residence) without any errors :(

Hi, the error is because the hostname_ids.txt file can't be found in your installation. I just pushed another commit to this PR branch. Please move the file to /var/lib/wgnord/hostname_ids.txt (like in the install instructions in the readme) and retry.

phirecc commented 2 months ago

Interesting idea using a static list but since some severs might change a API pull might be better, just my thoughts, I mean that's what I have and a solution that is best here is not jet decided on.

The static hostname->id list is only needed because the NordVPN API doesn't seem to support filtering by hostnames. The actual server information for the chosen server is still retrieved from the API and up-to-date.

I don't think the server ids would change. The list would only have to be updated periodically to account for new servers added by NordVPN. If we notice they frequently add servers, it might make sense to generate the hostname->id mapping within the script and update it if it's older than x days.

Your PR pulls servers from the API in chunks, but in the worst case it will still pull all 6467 of them. That's 20MB of JSON, each run of the script. Hence why I prefer this approach.

Bundy01 commented 2 months ago

@phirecc

Please move the file to /var/lib/wgnord/hostname_ids.txt (like in the install instructions in the readme) and retry.

It was done right from the start.

With the latest modification, it works. I've tested about 5 different servers.

Don't forget to also modify the help line with the s option in wgnord and README.md files.

Usage: wgnord [ l(ogin) | c(onnect) | d(isconnect) | a(ccount) | s(tatus) ]

Thanks.

EDIT: The short version works but serveur.norvpn.com does not. It's not too annoying unless you copy/paste the full name.

phirecc commented 2 months ago

EDIT: The short version works but serveur.norvpn.com does not. It's not too annoying unless you copy/paste the full name.

What is this hostname format you're referencing? wgnord looks for hostnames of the form

...
fr555.nordvpn.com|931418
ch219.nordvpn.com|931430
us5064.nordvpn.com|931490
uk813.nordvpn.com|932783
...

(It just greps and takes the first match)

Bundy01 commented 2 months ago

The short version ch219 works but the long one ch219.nordvpn.com, makes wgnord connect to the server closest to me (same country of residence).