Linux system tray Internet status icon

One of our members on the SLUG mailing list asked if anyone knew of a good way of notifying them when Internet connectivity is lost, in much of the same way as the network manager informs you that it has lost a local network connection, by displaying a notification in the system tray. I had a quick search of the Internet but couldn’t find anything useful, so I thought I would roll my own version using Python and GTK.

Basically the Python script below places an icon blue globe in the system tray when the PC is able to connect to the Internet and flashes a red stop icon when Internet connection is lost. To find out whether it has connection to the Internet it pings Googles DNS server ( every 10 seconds. There are a number of settings that be configured on lines 16 to 22 but the rest of the code should just work. This was developed and tested on Linux Mint 19.2 Cinnamon Version 4.2.4.

Copy the Python code below into a file and do a

chmod a+x and then to run it

./ &
#!/usr/bin/env python
Author:      Ian Crane
Date:        24 Nov 2019
Description: Displays a icon of the Internet connection status in the system tray of Linux

Original code from: <>

import gtk
import os
import time
import gobject

# Application settings
connectedIcon = gtk.STOCK_DISCONNECT # Yes this description does seem a little backwards
#disconnectedIcon = gtk.STOCK_CONNECT
disconnectedIcon = gtk.STOCK_DIALOG_ERROR
disconnectedIconFlashing = True
internetAddressToPing = ""
pingReplyCount = "1" # You may need to increase this if you have a flakey internet connection
internetCheckIntervalSeconds = 10

def message(data=None):
  "Function to display messages to the user."
  msg=gtk.MessageDialog(None, gtk.DIALOG_MODAL,gtk.MESSAGE_INFO, gtk.BUTTONS_OK, data)
def close_app(data=None):
def make_menu(event_button, event_time, data=None):
  menu = gtk.Menu()
  close_item = gtk.MenuItem("Close App")
  #Append the menu items  

  #Add callbacks
  close_item.connect_object("activate", close_app, "Close App")

  #Show the menu items
  #Popup the menu
  menu.popup(None, None, None, event_button, event_time)
def on_right_click(data, event_button, event_time):
    make_menu(event_button, event_time)
def on_left_click(event):
  message("Internet Connectivity monitor\n\nThis program shows the connectivity status of this PC to the Internet.\n\nInternet address to ping = " + internetAddressToPing + "\nPing reply count = " + pingReplyCount + "\nInternet check interval seconds = " + str(internetCheckIntervalSeconds)  + "\nFlash disconnected icon = " + str(disconnectedIconFlashing) + "\n\nThese settings can be changed by modifying the parameters in the top of of the Python file " + __file__)

def ping_internet():
  pingResponse = os.system("ping -c " + pingReplyCount + " " + internetAddressToPing + " > /dev/null 2>&1")
  if pingResponse == 0:
    #Host responed to ping
    systemTrayIcon.set_tooltip("Connected to Internet.")
    #Host didn't respond to ping
    systemTrayIcon.set_tooltip("Disconnected from Internet")

if __name__ == '__main__':
  systemTrayIcon = gtk.status_icon_new_from_stock(disconnectedIcon)
  systemTrayIcon.set_tooltip("Waiting for Internet status")
  systemTrayIcon.connect('popup-menu', on_right_click)
  systemTrayIcon.connect('activate', on_left_click)

%d bloggers like this: