Had some free time on my hands, so I have created a menubar “widget” to show current public IP address, ISP and Country (GeoIP based) using Hammerspoon and ip-api.com - free online GeoIP service. It was a fun little project to better get to know Hammerspoon and a good excuse to play with Lua for the first time :)
I find it useful when using VPN providers that route all traffic through VPN to check if my public IP has really changed and to which country / ISP as I am changing VPNs frequently.
And this is how it looks in your menubar:
Example in README.md shows how to setup auto refresh when your IPv4 address changes, but it should be easily modifiable if you need IPv6 change detection.
Example also waits for 10s after IP changes but clicking on the widget refreshes it if you don’t want to wait.
Project is here: https://github.com/asibin/hammerspoon-spoon-PublicIP
Let me know if you find it useful :)
How to install
Checkout repository into your Spoons directory (assuming you are using default spoons path):
git clone https://github.com/asibin/hammerspoon-spoon-PublicIP.git ~/.hammerspoon/Spoons/PublicIP.spoon
In your Hammerspoon config (~/.hammerspoon/init.lua
if default) file add:
hs.loadSpoon("PublicIP")
Reload you Hammespoon config if you don’t have auto-reload.
In case you want to watch for IPv4 address changes and auto refresh widget add this code block to your Hammerspoon confing file after loading spoon:
function networkChangedCallback(store, keys)
hs.timer.doAfter(10, function()
spoon.PublicIP.refreshIP()
end)
end
n = hs.network.configuration.open()
n:monitorKeys("State:/Network/Service/.*/IPv4", true)
n:setCallback(networkChangedCallback)
n:start()
Example of working Hammerspoon init.lua is in my dotfiles: https://github.com/asibin/dotfiles/blob/master/hammerspoon/init.lua