pia-foss / desktop

Private Internet Access - Desktop VPN Client for Windows/macOS/Linux
Other
263 stars 50 forks source link

how to get explicit region if set to auto #17

Closed piramiday closed 2 months ago

piramiday commented 3 years ago

running the latest PIA application on a headless server.

if I set the region to auto, how can I get the actual region I'm being connected to?

on the GUI it would show the region in parentheses, e.g. VPN Server: Auto (US California). on the command line piactl get region just returns auto, which does not help at all.

JonathonH-PIA commented 3 years ago

There isn't a get for this information right now, but it's possible using the dump daemon-state unstable command. That's considered "unstable" just because the JSON format may change in future releases, it usually doesn't change that much though.

Try piactl -u dump daemon-state | jq '.connectedConfig.vpnLocation' - you can also tack on .name to jq if you just want the name, the "friendly names" generated by piactl come from the display names (lowercased and with non-alpha chars replaced by -)

It's pretty easy to add gets if you'd like to take a look - one was just added in #15 , I'm sure we'll take a look at some point (there are a lot we'd like to add) but I'm not sure precisely when I'll get this into our schedule. In this case you'd be looking for client.connection().state.vpnLocation(), and there should be machinery in the get command to render the pretty name from that location object.

piramiday commented 7 months ago

it does not look like .name is there anymore, should I look someplace different?

user@host: ~$ piactl --version
3.5.1+07760

user@host:~$ piactl -u dump daemon-state | jq .connectedConfig.vpnLocation
{
  "autoSafe": 
  "dedicatedIp": 
  "geoLocated": 
  "hasShadowsocks": 
  "id": 
  "latency": 
  "offline": 
  "portForward": 
}

(I removed all values after the : sign, so that is not valid JSON anymore.)

kp-michele-emiliani commented 2 months ago

Hello! I believe the field you are looking for is "id". Is that what you were looking for? This is the output of the command and it contains the region name (even when connected to auto)

$ piactl -u dump daemon-state | jq .connectedConfig.vpnLocation
{
  "autoSafe": true,
  "dedicatedIp": "",
  "geoLocated": false,
  "hasShadowsocks": false,
  "id": "uk_southampton",
  "latency": 59,
  "offline": false,
  "portForward": true
}

I did find another bug while looking at this though, "portForward" is always true so will make a ticket for that :)

piramiday commented 2 months ago

there used to be a name which was user-friendlier, but sure, id can be used to extract roughly the same information.