✅ Conky setting get/show location info from (Pia) VPN server

Add functionality to your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

✅ Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

By adding (see code lines) in conky, I get information from the locations that Pia server is connecting to.
Set the interval to 300 seconds (5 minutes), but don't really need that interval, as long as I don't switch to another server.
What is advisable set the interval time to 0 or do I have to increase it to 7200 or more, for example.

Code: Select all

Land: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'} 

Code: Select all

Stad: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "city" | awk -F'"' '{print $4}'} 

Code: Select all

Regio: $alignr ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "region" | awk -F'"' '{print $4}'}
Image
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

You can not use 0 because it is less than the update_interval variable, which is how these 'exec' functions are defined, so probably use a high number.

Instead, maybe you want to try something like $no_update:

Code: Select all

Land: $alignr ${no_update ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'}}
-so it will run once and not run after that.

edit: i guess that syntax was wrong
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

zcot wrote: Wed Oct 16, 2019 12:53 pm

Code: Select all

Land: $alignr ${no_update ${execi 300 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'}}
edit: i guess that syntax was wrong
Thanks for your response but unfortunately you are right your code isn't working :wink:
I decided to set the interval in my own code to 60 seconds
User avatar
AndyMH
Level 21
Level 21
Posts: 13503
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH »

Relevant line from my conky:

Code: Select all

Public IP: $alignr ${execi 43200 curl ifconfig.me/ip}
i.e. every 12 hours, but I don't expect my external IP to change.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

Yea, sorry, I didn't test that line. :roll:

But here, I scratched this one up, and actually tested it. :lol:

I always feel creepy about seeing what appears to be more processing than needed. Although in this case, it is barely even perceptible. I did run timing on that code shown and the total of the 3 lines is averaging about 0.000022 microseconds on this test, so that feels good in the end.

But my thinking was, can we get away with only making the wget call once? and is that more effective? less usage? -and then pull each of the 3 pieces of info from that. To me, it "feels" better anyway. Although I admit sometimes I have tried to work something out and it only makes matters worse, but a lot of times it can be a nice addition. Or at least fun to work out the process, if nothing else.

So I did a lua script and added the following to the conky config file:

Code: Select all

${no_update ${lua conky_vpninfo}}\
Land: ${lua conky_vpn_get_country}
Stad: ${lua conky_vpn_get_city}
Regio: ${lua conky_vpn_get_state}
And in the conky.config section I have:

Code: Select all

conky.config = {
    lua_load = 'vpninfo.lua',
...
And vpninfo.lua:

Code: Select all


local datat = {}

function conky_vpninfo()

    local td = ""
    local f = io.popen("wget -qO- ipinfo.io")

    -- info is "parameter": "data", like json output so strip leading 2 quotes
    for line in f:lines() do
        td = td .. string.gsub(line, "\"", "", 2)
    end

    f:close()

    -- also replace : with = and string can become functional lua table
    datat = loadstring("return " .. string.gsub(td, ":", "="))()

    return
end


function conky_vpn_get_country()

    return tostring(datat.country)

end

function conky_vpn_get_state()

    return tostring(datat.region)

end

function conky_vpn_get_city()

    return tostring(datat.city)

end
suprisingly, these two blocks runs very close to the same amount of processing timings. Here are some timing samples:

Code: Select all

elapsed time raw: 0.000018
elapsed time lua: 0.000013

elapsed time raw: 0.000024
elapsed time lua: 0.000022

elapsed time raw: 0.000015
elapsed time lua: 0.000013

elapsed time raw: 0.000023
elapsed time lua: 0.000024

elapsed time raw: 0.000015
elapsed time lua: 0.000012

elapsed time raw: 0.000024
elapsed time lua: 0.000022

elapsed time raw: 0.000024
elapsed time lua: 0.000023

elapsed time raw: 0.000015
elapsed time lua: 0.000012

elapsed time raw: 0.000024
elapsed time lua: 0.000021

elapsed time raw: 0.000023
elapsed time lua: 0.000021

elapsed time raw: 0.000023
elapsed time lua: 0.000022

elapsed time raw: 0.000024
elapsed time lua: 0.000021

elapsed time raw: 0.000025
elapsed time lua: 0.000022

elapsed time raw: 0.000024
elapsed time lua: 0.000019

elapsed time raw: 0.000024
elapsed time lua: 0.000021

elapsed time raw: 0.000025
elapsed time lua: 0.000021

elapsed time raw: 0.000022
elapsed time lua: 0.000021
So, it was fun anyway. :wink:

And then maybe work out a stop/restart script for that conky in case the vpn has changed.
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

zcot wrote: Thu Oct 17, 2019 11:26 pm I always feel creepy about seeing what appears to be more processing than needed. Although in this case, it is barely even perceptible.

But my thinking was, can we get away with only making the wget call once? and is that more effective? less usage? -and then pull each of the 3 pieces of info from that.
So I did a lua script and added the following to the conky config file:
I have attempted to combine those 3 lines in conky with 1 Wget request, so far this has not been successful,leave it there for now.
Your Lua script is well thought out and looks good to me,nice thinking

"I love it when a plan comes together!" - Kolonel John "Hannibal" Smith catchphrase
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

Maybe one day I will commit to learn about regex, but I always avoid it since I'm scared of it. :shock: Until then, I have to type out the longer form.
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

The PIA server location brought back to 1 line in Conky

Code: Select all

Locatie server: $alignr ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "city" | awk -F'"' '{print $4}'} - ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "region" | awk -F'"' '{print $4}'} - ${execi 60 wget -qO- ipinfo.io 2> /dev/null | grep "country" | awk -F'"' '{print $4}'} 
Image
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

I did some messing around. One single execi call, and a single wget call. I have this:

Code: Select all

stad/regio/land:
${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": "|"region": "|"country": ")(\w+)'}
User avatar
AndyMH
Level 21
Level 21
Posts: 13503
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH »

Thanks for that, I'll be amending my conky to show city/country.
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

AndyMH, you are welcome! It was fun figuring out that much. :D

I'm weak with it, but I was able to get that far anyway. Not sure about efficiency though in comparison to other options like grep, sed, and awk, although that is faster than the other two examples from above. I'm guessing someone in the bash and scripts forum could do something like this with relative ease, and choose the most effective way to do it.

timing sample:

Code: Select all

elapsed time reg: 0.000006
elapsed time reg: 0.000010
elapsed time reg: 0.000009
And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.
User avatar
AndyMH
Level 21
Level 21
Posts: 13503
Joined: Fri Mar 04, 2016 5:23 pm
Location: Wiltshire

Re: Conky setting get/show location info from (Pia) VPN server

Post by AndyMH »

I'm ok with grep, usually, but when it comes to sed and awk I normally try and fail, try again, fail again (and this is after reading the man pages and searching the web). When I've done this several times, then I ask here and I've always had a rapid response. :)
Thinkcentre M720Q - LM21.3 cinnamon, 4 x T430 - LM21.3 cinnamon, Homebrew desktop i5-8400+GTX1080 Cinnamon 19.0
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

zcot wrote: Wed Oct 30, 2019 6:16 pm And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.
Thanks!
I changed the format to get the conky output in 1 line

Code: Select all

Locatie VPN Server: $alignr ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="region": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="country": ")(\w+)'}   
User avatar
zcot
Level 9
Level 9
Posts: 2781
Joined: Wed Oct 19, 2016 6:08 pm

Re: Conky setting get/show location info from (Pia) VPN server

Post by zcot »

Gruppo Sportivo wrote: Thu Oct 31, 2019 4:07 pm
zcot wrote: Wed Oct 30, 2019 6:16 pm And there's probably a simple way to format that output better, other than it coming out on 3 individual lines.
Thanks!
I changed the format to get the conky output in 1 line

Code: Select all

Locatie VPN Server: $alignr ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="region": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="country": ")(\w+)'}   
Yes! :wink:

Excellent, indeed! :D
User avatar
Gruppo Sportivo
Level 4
Level 4
Posts: 278
Joined: Sun May 28, 2017 4:14 am
Location: 🇳🇱

Re: Conky setting get/show location info from (Pia) VPN server

Post by Gruppo Sportivo »

Pia protocol converted from OpenVpn to WireGuard.

To make the locations (City,Region and Country) of Pia WireGuard servers visible,changed the line ${if_up tun0} to ${if_up wgpia0}.

Code: Select all

${color #4e6969}${font conkysymbols:size=10}i${font}${color} Netwerk
${color #4e6969}${font ConkyColors:size=10}r${font}${color} ISP: $alignr KPN
${color #4e6969}${font conkysymbols:size=10}I${font}${color} IP adres: $alignr ${addr enp1s0}
${if_up wgpia0}
${color #4e6969}${font conkysymbols:size=10}i${font}${color} VPN
${color #4e6969}${font ConkyColors:size=10}r${font}${color} ISP: $alignr PIA 
${color #4e6969}${font ConkyColors:size=10}r${font}${color} Protocol: $alignr WireGuard
${color #4e6969}${font conkysymbols:size=10}I${font}${color} IP adres: ${alignr}${execi 60 curl -s ipinfo.io/ip}
${color #4e6969}${font conkysymbols:size=10}i${font}${color} Locatie VPN Server: $alignr${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="city": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="region": ")(\w+)'} - ${execi 9001 wget -qO- ipinfo.io 2> /dev/null | grep -oP '(?<="country": ")(\w+)'} 
${else}${color DC143C}${font ConkyColors:size=10}r${font}${color} ISP: $alignr PIA-VPN Verbroken/Gesnoozed
$endif
Edit: Screenprint Conky
Image
Locked

Return to “Compiz, Conky, Docks & Widgets”