arpscan_tracker.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:home-assistant-custom-components 作者: cyberjunky 项目源码 文件源码
def _update_info(self):
        """Scan the network for devices.

        Returns boolean if scanning successful.
        """
        _LOGGER.debug("Update_info called")

        options = self._options

        last_results = []
        exclude_hosts = self.exclude

        scandata = subprocess.getoutput("arp-scan "+options)

        now = dt_util.now()
        for line in scandata.splitlines():
            ipv4 = re.findall(r'[0-9]+(?:\.[0-9]+){3}', line)
            if not ipv4:
                continue

            parts = line.split()
            ipv4 = parts[0]
            for exclude in exclude_hosts:
                if exclude == ipv4:
                    _LOGGER.debug("Excluded %s", exclude)
                    continue

            name = ipv4
            mac = parts[1]
            last_results.append(Device(mac, name, ipv4, now))

        self.last_results = last_results

        _LOGGER.debug("Update_info successful")
        return True
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号