Changeset 949

Show
Ignore:
Timestamp:
08/07/08 15:00:43 (4 months ago)
Author:
mariodebian
Message:

tcosmonitor (0.2.16~rc5)

  • ping.py TcosCommon?.py debian/control:
    • Replace old code to get interfaces and IP addr with python-netifaces (in TCOS mirror)
Location:
trunk/tcosmonitor
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/tcosmonitor/TcosCommon.py

    r944 r949  
    3434from gettext import gettext as _ 
    3535 
     36import netifaces 
    3637 
    3738from time import sleep 
     
    112113    def get_ip_address(self, ifname): 
    113114        print_debug("get_ip_address() ifname=%s" %(ifname) ) 
     115        if not ifname in netifaces.interfaces(): 
     116            return None 
     117        ip=netifaces.ifaddresses(ifname) 
     118        if ip.has_key(netifaces.AF_INET): 
     119            return ip[netifaces.AF_INET][0]['addr'] 
     120        return None 
     121        """ 
     122        old code 
     123        print_debug("get_ip_address() ifname=%s" %(ifname) ) 
    114124        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
    115125        #print_debug("get_ip_address() iface=%s" %ifname) 
     
    119129            struct.pack('256s', ifname[:15]) 
    120130        )[20:24]) 
     131        """ 
    121132 
    122133    def GetAllNetworkInterfaces(self): 
     134        self.vars["allnetworkinterfaces"]=[] 
     135        for dev in netifaces.interfaces(): 
     136            if not dev in shared.hidden_network_ifaces: 
     137                self.vars["allnetworkinterfaces"].append(dev) 
     138                ip=netifaces.ifaddresses(dev) 
     139        print_debug ( "GetAllNetworkInterfaces() %s" %( self.vars["allnetworkinterfaces"] ) ) 
     140        return self.vars["allnetworkinterfaces"] 
     141        """ 
    123142        self.vars["allnetworkinterfaces"]=[] 
    124143        d="/sys/class/net/" 
     
    129148        print_debug ( "GetAllNetworkInterfaces() %s" %( self.vars["allnetworkinterfaces"] ) ) 
    130149        return self.vars["allnetworkinterfaces"] 
     150        """ 
    131151 
    132152    def get_my_local_ip(self, last=True, force=False): 
     
    135155            self.vars["local_ip"]=[] 
    136156            for dev in self.GetAllNetworkInterfaces(): 
     157                ip=self.get_ip_address(dev) 
     158                if ip: 
     159                    self.vars["local_ip"].append(ip) 
     160                """ 
    137161                try: 
    138162                    ip=self.get_ip_address(dev) 
     
    141165                    print_debug("get_my_local_ip() Exception, dev=%s error=%s"%(dev,err) ) 
    142166                    pass 
     167                """ 
    143168        if last: 
    144169            return self.vars["local_ip"][0] 
     
    150175        if "local_ip" in self.vars: 
    151176            return self.vars["local_ip"] 
    152         return get_my_local_ip(last=False) 
     177        return self.get_my_local_ip(last=False) 
    153178 
    154179    def get_display(self, ip_mode=True): 
     
    249274    #print app.get_all_my_ips() 
    250275    #print app.get_extensions() 
    251     app.init_all_extensions(extfilter="menu_one") 
    252     print app.get_icon_theme() 
     276    #app.init_all_extensions(extfilter="menu_one") 
     277    #print app.get_icon_theme() 
     278    #print app.get_all_my_ips() 
     279    #print app.GetAllNetworkInterfaces() 
     280    print app.get_ip_address('eth0') 
     281    print app.get_ip_address('eth1') 
     282    print app.get_ip_address('br0') 
     283    print app.get_ip_address('br0:0') 
  • trunk/tcosmonitor/debian/changelog

    r948 r949  
     1tcosmonitor (0.2.16~rc5) unstable; urgency=low 
     2 
     3  * ping.py TcosCommon.py debian/control: 
     4    - Replace old code to get interfaces and IP addr with python-netifaces (in TCOS mirror) 
     5 
     6 -- Mario Izquierdo (mariodebian) <mariodebian@gmail.com>  Thu, 07 Aug 2008 14:58:45 +0200 
     7 
    18tcosmonitor (0.2.16~rc4) unstable; urgency=low 
    29 
  • trunk/tcosmonitor/debian/control

    r914 r949  
    1313Architecture: all 
    1414Depends:  gksu | kdebase-bin, zenity, dbus, 
    15           python-dbus | python2.4-dbus, python-gtk2, python-glade2,  
     15          python-dbus | python2.4-dbus, python-gtk2, python-glade2, python-netifaces,  
    1616          x11vnc, lsb-base (>= 3.0-6), python-notify, python-gnome2-extras,  
    1717          notification-daemon, libnotify-bin, tcos-core ( >= 0.89~rc0), python-utmp,  
  • trunk/tcosmonitor/ping.py

    r944 r949  
    2020from time import sleep 
    2121from subprocess import Popen, PIPE, STDOUT 
     22 
     23import netifaces 
    2224 
    2325if "DISPLAY" in os.environ: 
     
    137139  
    138140    def get_ip_address(self, ifname): 
     141        print_debug("get_ip_address() ifname=%s" %(ifname) ) 
     142        if not ifname in netifaces.interfaces(): 
     143            return None 
     144        ip=netifaces.ifaddresses(ifname) 
     145        if ip.has_key(netifaces.AF_INET): 
     146            return ip[netifaces.AF_INET][0]['addr'] 
     147        return None 
     148        """ 
     149        old code 
    139150        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 
    140151        try: 
     
    148159            print_debug("get_ip_address() ifname %s don't have ip address, error=%s"%(ifname,err)) 
    149160        return ip 
     161        """ 
    150162 
    151163 
    152164    def get_server_ips(self): 
     165        IPS=[] 
     166        for dev in netifaces.interfaces(): 
     167            if not dev in shared.hidden_network_ifaces: 
     168                print_debug("get_server_ips() add interface %s"%dev) 
     169                ip=netifaces.ifaddresses(dev) 
     170                if ip.has_key(netifaces.AF_INET): 
     171                    print_debug("get_server_ips() iface=%s data=%s"%(dev,ip[netifaces.AF_INET] )) 
     172                    IPS.append(ip[netifaces.AF_INET][0]['addr']) 
     173        return IPS 
     174        """ 
     175        old code 
    153176        IPS=[] 
    154177        for dev in os.listdir("/sys/class/net"): 
     
    162185        print_debug("get_server_ips() IPS=%s"%IPS) 
    163186        return IPS 
     187        """ 
    164188 
    165189 
     
    231255    #PingPort("192.168.0.5", 6000, 0.5).get_status() 
    232256    #PingPort("192.168.0.1", 6000, 0.5).get_status() 
    233     PingPort(sys.argv[1], sys.argv[2], 0.5).get_status() 
    234     #app=Ping(None) 
    235     #print app.get_server_ips() 
     257    #PingPort(sys.argv[1], sys.argv[2], 0.5).get_status() 
     258    app=Ping(None) 
     259    print app.get_server_ips() 
     260    print app.get_ip_address('eth0') 
     261    print app.get_ip_address('br0') 
     262