networking - Limited or no connectivity notification in Unity for 16.04 - Ask Ubuntu


i having trouble lack of feature on unity 16.04. if wifi active @ router level, when there no internet access ( isp fails @ times ), there no way can know in unity 16.04. 2009 born windows 7 notifies if there " no internet access ".

is there other file manager or de can use ? or, modification available 16.04 unity ? thanks.

the simplest way use ping -c4 google.com test internet connection. if can reach out beyond router url, have internet access. can adapted script periodically pings site choose. i've different idea.

here's top-panel indicator that'll periodically request internet connection. if internet connection goes down, it's icon change warning sign. uses standard icon names, no need add additional icons.

save file, make sure has executable permissions chmod +x interwebs-indicator (from terminal) or via right-click menu in file manager. run manually in terminal

python3 intwerwebs-indicator 

or

./interwebs-indicator 

if have given executable permissions.

you can make start automatically on gui login ,too.

simple , easy use.

#!/usr/bin/env python3 # -*- coding: utf-8 -*-  # # author: serg kolo , contact: 1047481448@qq.com # date: november 3rd, 2016 # purpose: appindicator testing internet connection # tested on: ubuntu 16.04 lts # # # licensed under mit license (mit). # see included license file or notice below. # # copyright © 2016 sergiy kolodyazhnyy # # permission hereby granted, free of charge, person obtaining copy # of software , associated documentation files (the "software"), deal # in software without restriction, including without limitation rights # use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of software, , permit persons whom software # furnished so, subject following conditions: # # above copyright notice , permission notice shall included # in copies or substantial portions of software. # # software provided "as is", without warranty of kind, express or # implied, including not limited warranties of merchantability, # fitness particular purpose , noninfringement. in no event shall # authors or copyright holders liable claim, damages or other # liability, whether in action of contract, tort or otherwise, arising from, # out of or in connection software or use or other dealings in # software. import gi gi.require_version('appindicator3', '0.1') gi.require_version('notify', '0.7') gi.repository import glib glib gi.repository import appindicator3 appindicator gi.repository import gtk gtk gi.repository import gio gi.repository import gdk import urllib.request urllib2  class interwebsidicator(object):      def __init__(self):         self.app = appindicator.indicator.new(             'interwebs-indicator', "gtk-network",             appindicator.indicatorcategory.hardware         )          self.app.set_attention_icon('dialog-warning')         #self.app.set_status(appindicator.indicatorstatus.active)         self.make_menu()         self.update()      def add_menu_item(self, menu_obj, item_type, image, label, action, args):         """ dynamic function can add menu items depending on             item type , other arguments"""         menu_item, icon = none, none         if item_type gtk.imagemenuitem , label:             menu_item = gtk.imagemenuitem.new_with_label(label)             menu_item.set_always_show_image(true)             if '/' in image:                 icon = gtk.image.new_from_file(image)             else:                 icon = gtk.image.new_from_icon_name(image, 48)             menu_item.set_image(icon)         elif item_type gtk.imagemenuitem , not label:             menu_item = gtk.imagemenuitem()             menu_item.set_always_show_image(true)             if '/' in image:                 icon = gtk.image.new_from_file(image)             else:                 icon = gtk.image.new_from_icon_name(image, 16)             menu_item.set_image(icon)         elif item_type gtk.menuitem:             menu_item = gtk.menuitem(label)         elif item_type gtk.separatormenuitem:             menu_item = gtk.separatormenuitem()         if action:             menu_item.connect('activate', action, *args)          menu_obj.append(menu_item)         menu_item.show()       def add_submenu(self,top_menu,label):         menuitem = gtk.menuitem(label)         submenu = gtk.menu()         menuitem.set_submenu(submenu)         top_menu.append(menuitem)         menuitem.show()         return submenu      def make_menu(self):          self.app_menu = gtk.menu()         self.add_menu_item(self.app_menu,gtk.imagemenuitem,'exit','quit',self.quit,[none])         self.app.set_menu(self.app_menu)      def check_connection(self,*args):         try:             url = urllib2.urlopen('http://google.com')             page = url.read()         except urllib2.httperror:             print('>>> err:')             self.app.set_status(appindicator.indicatorstatus.attention)             #self.app.attention-icon('network-error')         except exception e:             print('>>> exception:',e)         else:             print('>>> ok')              self.app.set_status(appindicator.indicatorstatus.active)             self.app.set_icon('network')       def callback(self,*args):          timeout = 5         glib.timeout_add_seconds(timeout, self.update)      def update(self,*args):         self.check_connection()          self.callback() # general purpose functions        def quit(self,*args):         gtk.main_quit()       def run(self):         """ launches indicator """         try:             gtk.main()         except keyboardinterrupt:             pass      def quit(self, *args):         """ closes indicator """         gtk.main_quit()   def main():     """ defines program entry point """     indicator = interwebsidicator()     indicator.run()  if __name__ == '__main__':   try:     main()   except  keyboardinterrupt:     gtk.main_quit() 

Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User