-
-
Save SergKolo/6348a4d840dfa316fdf532829c92f574 to your computer and use it in GitHub Desktop.
IP Address AppIndicator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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