コード例 #1
0
ファイル: scanner.py プロジェクト: panzerhong/elmocut
    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
ファイル: scanner.py プロジェクト: panzerhong/elmocut
    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
ファイル: scanner.py プロジェクト: panzerhong/elmocut
    def init(self):
        """
        Intializing Scanner
        """
        self.router_ip = conf.route.route("0.0.0.0")[2]
        self.router_mac = GLOBAL_MAC

        self.my_ip = get_my_ip()
        self.my_mac = good_mac(Ether().src)
        
        self.perfix = self.router_ip.rsplit(".", 1)[0]
        self.generate_ips()

        self.add_me()
        self.add_router()