Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Forked from nathan-osman/ip-indicator.py
Created August 1, 2016 20:53
Show Gist options
  • Save SergKolo/6348a4d840dfa316fdf532829c92f574 to your computer and use it in GitHub Desktop.
Save SergKolo/6348a4d840dfa316fdf532829c92f574 to your computer and use it in GitHub Desktop.
IP Address AppIndicator
#!/usr/bin/env python2
import appindicator
import gtk
import urllib2
class IPIndicator(appindicator.Indicator):
"""
An indicator displaying public IP address.
"""
def __init__(self):
super(IPIndicator, self).__init__(
"ip-indicator",
"applications-internet",
appindicator.CATEGORY_APPLICATION_STATUS
)
# Create the quit menu item
menu, quit = gtk.Menu(), gtk.MenuItem('Quit')
quit.connect('activate', gtk.main_quit)
quit.show()
menu.append(quit)
self.set_menu(menu)
self.set_status(appindicator.STATUS_ACTIVE)
def run(self):
self._refresh()
gtk.timeout_add(600, self._refresh)
gtk.main()
def _refresh(self):
self.set_label("[Refreshing...]")
try:
ip = '[%s]' % urllib2.urlopen('http://icanhazip.com').read().strip()
except:
ip = '[Error]'
self.set_label(ip)
if __name__ == '__main__':
IPIndicator().run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment