How to Display Your Public IP Address in Polybar⚓
This article will explain the steps needed in order to display the public IP address of your computer in Polybar.
There are a number of ways to obtain your public IP address, but the tricky part is finding a service that can actually display it properly in Polybar. OpenDNS and Google both used to have sites specifically for this, but have both decommissioned the service.
My favorite way of obtaining my public IP address by far is using
curl ifconfig.io. It's incredibly slick and gives you just the IP address, without any filler. However, when applied to Polybar, it gives too much information and in my case, seems to overwhelm Polybar either by crashing or by displaying a long error that gets truncated at a certain point.
I was able to locate another service called IP Echo. They offer a similar service to ifconfig.io, but is able to display the IP address properly. The proper syntax for obtaining just the IP address is as follows:
This will now need to be added as a Polybar module.
Creating a Polybar Module⚓
- Open a terminal and navigate to the Polybar modules directory
- Once in the directory, create a new configuration file for the module.
- In the config file, add the following syntax:
- Save the file.
Add PublicIP Module to Polybar⚓
Although the config file has been created, it's not yet recognized by Polybar since it hasn't been added to the modules config file.
- Navigate to
- Inside the
modules.conffile, add the following two lines to the file. I added them in alphabetical order, but the order doesn't matter.
- Save the file.
Now the module is recognized by Polybar, but it still needs to be recognized inside the config file located at
~/.config/polybar/config. Once that file is opened, scroll all the way to the bottom and add the module to the specific position you want it to reside on Polybar. I've added PublicIP to the right side of Polybar because it makes sense to me, but it can be added in any location depending on preference.
My config file looks like the following:
; File Includes
include-file = $HOME/.config/polybar/master.conf
include-file = $HOME/.config/polybar/modules.conf
; Openbox Bars
inherit = bar/master
; Use $ xrandr -q | grep " connected" | cut -d ' ' -f1
;tray-position = center
;tray-transparent = true
;tray-background = #0063ff
modules-left = manjaro workspaces
modules-center = spotify
modules-right = weather pkg redshift memory temperature publicip coreuse pulseaudio clock
At this point, reload Polybar and the PublicIP module will now be visible and displaying the proper public IP address.