コード例 #1
0
    def run(self):

     #Internet Diagnostic
        if not getoutput("ping www.google.com -c1 >/dev/null 2>&1 ; echo $?")[-1]=="0": #this must return 0 to have internet
            if not getoutput("ping www.kademar.org -c1 >/dev/null 2>&1 ; echo $?")[-1]=="0": #check with various servers
                if not getoutput("ping www.yahoo.com -c1 >/dev/null 2>&1 ; echo $?")[-1]=="0": #if previous fails
                    internet=False
                else:
                    internet=True
            else:
                internet=True
        else:
            internet=True

        self.emit(SIGNAL("DiagInternet"), internet)  #Emit Internet Diagnostic

     #Router Diagnostic
        netdevices=getNetworkDevices()
        ip_router=eth_provider=ip_eth_provider=""
        router=False
        for eth in netdevices:
            info=getoutput("arp -i "+eth+" 2>/dev/null | grep "+eth+" 2>/dev/null").split()
            if len(info)>1:
                if getoutput("ping "+info[0]+" -c1 >/dev/null 2>&1 ; echo $?")[-1]=="0": #if we have connection with router
                    eth_provider=eth
                    ip_eth_provider=getoutput("ifconfig "+eth_provider+" | grep Bcast | cut -f2 -d: | cut -f1 -d\ ") #get your IP
                    mac_eth_provider=getoutput("cat /sys/class/net/"+eth_provider+"/address") # get ethernet MAC
                    ip_router=info[0]  # get router IP
                    mac_router=info[2]  # get router MAC
                    router=True #check that we have found a router
                    break

     #This means that we cannot get router information
        if not router:
            #print "second router information"
            a=getoutput("""arp -a >/dev/null 2>&1 ; arp 2>/dev/null | while read line; do if [ "`echo $line | awk ' { print $4 } '`" = "C" ]; then echo $line | awk ' { print $1" "$5 } '; fi; done""").split()
            if len(eth_provider)>0:  #if found and eth_provider
                eth_provider=a[1]
                ip_eth_provider=getoutput("ifconfig "+eth_provider+" | grep Bcast | cut -f2 -d: | cut -f1 -d\ ") #get your IP
                mac_eth_provider=getoutput("cat /sys/class/net/"+eth_provider+"/address")
                ip_router=a[0]
                mac_router=""
                router=True

        self.emit(SIGNAL("DiagRouter"), router, ip_router, eth_provider, ip_eth_provider)  #Emit Router Diagnostic

        #Here you can read if any ethernet is configured and pass a fail diagnostic
        if not router: 
            #momentaniously only pass fail, does not check local IP if don't have connection to router
            self.emit(SIGNAL("DiagFinal"), "fail")
        else:
            self.emit(SIGNAL("DiagFinal"), "ok2")
コード例 #2
0
    def enterPageEvent(self, page):
        #this function makes things when enter to a concrete page

        if page==1:  #entered to page Devices
            self.ui.list_net_dev.blockSignals(True)
            self.real_devices=[]
            devices=getNetworkDevices() #get network devices
            self.ui.list_net_dev.clear()
            for dev in devices:
                wireless=path.exists("/sys/class/net/"+dev+"/wireless")  #this interface is wireless?
                if wireless:
                    icon=self.img_wireless
                else:
                    icon=self.img_ethernet
                vendor=grepNetInterfaceInformation(dev, "vendor")
                product=grepNetInterfaceInformation(dev, "product")
                a=QListWidgetItem(self.ui.list_net_dev)
                a.setText(dev+": "+vendor+"\n"+product)
                a.setIcon(QIcon(icon))
                self.ui.list_net_dev.addItem(a)
                # eth, true/false, vendor, product
                d=[dev, wireless, vendor, product]
                self.real_devices.append(d)
            self.ui.b_next.setEnabled(False) #disable next button
            self.ui.list_net_dev.blockSignals(False)
                #get hal information about it
            #restart IP parameters
            self.restartIpParameters()

        elif page==2:  #entered to page Wireless networks
            self.reload_wifi_list()
            #restart IP parameters
            self.restartIpParameters()
        elif page==3:
            self.grepOldDeviceSettings()
            self.ui.le_ip.setText(self.returnOldSetting("address"))
            self.ui.le_netmask.setText(self.returnOldSetting("netmask"))
            self.ui.le_gateway.setText(self.returnOldSetting("gateway"))
            self.ui.le_custom_dns.setText(self.returnOldSetting("dns-nameservers"))