Пример #1
0
    def devices_appender(self, scan_result):
        """
        Append scan results to self.devices
        """
        self.devices = []
        unique = []

        # Sort by last part of ip xxx.xxx.x.y
        scan_result = sorted(
            scan_result,
            key=lambda i:int(i[0].split('.')[-1])
        )
        
        for ip, mac in scan_result:
            mac = good_mac(mac)

            # Store gateway
            if ip == self.router_ip:
                self.router_mac = mac
                continue
            
            # Skip me or duplicated devices
            if ip == self.my_ip or mac in unique:
                continue
            
            # update same device with new ip
            if self.old_ips.get(mac, ip) != ip:
                self.old_ips[mac] = ip
                unique.append(mac)

            self.devices.append(
                {
                    'ip':     ip,
                    'mac':    good_mac(mac),
                    'vendor': get_vendor(mac),
                    'type':   'User',
                    'admin':  False
                }
            )
        
        # Remove device with old ip
        for device in self.devices[:]:
            mac, ip = device['mac'], device['ip']
            if self.old_ips.get(mac, ip) != ip:
                self.devices.remove(device)
        
        # Re-create devices old ips dict
        self.old_ips = {d['mac']: d['ip'] for d in self.devices}

        self.add_me()
        self.add_router()

        # Clear arp cache to avoid duplicates next time
        if unique:
            self.flush_arp()
Пример #2
0
    def add_router(self):
        """
        Get Gateway info and append to self.devices
        """
        self.router = {
            'ip':       self.router_ip,
            'mac':      good_mac(self.router_mac),
            'vendor':   get_vendor(self.router_mac),
            'type':     'Router',
            'admin':    True
        }

        self.devices.insert(0, self.router)
Пример #3
0
 def add_me(self):
     """
     Get My info and append to self.devices
     """
     self.me = {
         'ip':       self.my_ip,
         'mac':      self.my_mac,
         'vendor':   get_vendor(self.my_mac),
         'type':     'Me',
         'admin':    True
     }
     
     self.devices.insert(0, self.me)