Last active
August 29, 2015 13:56
-
-
Save TamasBarta/8968204 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/python | |
# -*- coding: UTF-8 -*- | |
import urllib2 | |
import appindicator | |
import pynotify | |
import gtk | |
from concurrent import futures | |
import socket | |
class Checker: | |
last_check = True | |
a = None | |
def internet_on(self): | |
try: | |
response=urllib2.urlopen('http://74.125.228.100',timeout=2) | |
return True | |
except urllib2.URLError as err: pass | |
except socket.timeout as err: pass | |
return False | |
def quit(self, item): | |
gtk.main_quit(); | |
def check(self): | |
current_check = self.internet_on() | |
if self.last_check != current_check: | |
self.last_check = current_check | |
pynotify.init('netcheckindicator') | |
if current_check: | |
body = 'Van internetkapcsolat' | |
self.a.set_icon('ubuntuone-client-idle') | |
else: | |
body = 'Nincs internetkapcsolat' | |
self.a.set_icon('ubuntuone-client-error') | |
n = pynotify.Notification('Internetkapcsolat ellenőrző', | |
body, | |
'network') | |
n.show() | |
gtk.timeout_add(3000, self.check) | |
def main(self): | |
# print what | |
self.a = appindicator.Indicator('netcheckindicator', 'ubuntuone-client-idle', appindicator.CATEGORY_APPLICATION_STATUS) | |
self.a.set_status( appindicator.STATUS_ACTIVE ) | |
m = gtk.Menu() | |
mQuit = gtk.MenuItem('Kilépés') | |
mQuit.show() | |
mQuit.connect('activate', self.quit) | |
m.append(mQuit) | |
self.a.set_menu(m) | |
gtk.timeout_add(3000, self.check) | |
gtk.main() | |
checker = Checker() | |
checker.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Threw together in 10 minutes, because my ISP (T-Home) is a dick, and my internet connection is totally unreliable. Does nothing else, but show an indicator on my Ubuntu 13.10 installation, and notifies me, if internet access is shut down, or is available again.