An elementary tool to detect Linux active interfaces change and get a country yours public IP belongs to.
I need this as I often use some VPN tunnel and want to see my current "location" at i3 status bar.
The code:
- Checks number of active network connections.
- If number changed app does HTTP request to external API returning geo location of IP address from where request comes.
- Updates location country at
/tmp/whereamifromfile.
Currently https://ipinfo.io/ is used.
Using command line arguments or environment variable you may change application behavior. For example to get more information and use it any way you like:
$ FILE=/tmp/test URL=http://ipinfo.io/ ./target/debug/whereamifromCreates:
{
"ip": "77.88.99.100",
"city": "Orgrimmar",
"region": "Durotar",
"country": "Kalimdor",
"loc": "45.00,65.00",
"org": "The Horde",
"postal": "0000",
"timezone": "Azeroth",
"readme": "https://ipinfo.io/missingauth"
}