arpspoof.py 文件源码

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

项目:HomeAssistant-CustomComponents 作者: pilotak 项目源码 文件源码
def setup_platform(hass, config, add_devices,
                   discovery_info=None):
    """Setup"""
    _LOGGER.debug("Starting up")

    import validators

    if DATA_ARPSPOOF not in hass.data:
        _LOGGER.error("ARP component not initialised!")
        return False

    devices = config.get(CONF_DEVICES, {})
    switches = []
    data = hass.data[DATA_ARPSPOOF]

    for object_id, device_config in devices.items():
        address = device_config.get(CONF_ADDRESS)
        friendly_name = device_config.get(CONF_FRIENDLY_NAME)
        type = -1

        if validators.ipv4(address):
            type = 0
        elif validators.mac_address(address):
            type = 1

        if type > -1:
            _LOGGER.debug("Adding '%s' as switch '%s'",
                          address, friendly_name)

            switches.append(
                ArpSpoofSwitch(
                    data,
                    object_id,
                    friendly_name,
                    address,
                    type,
                    device_config.get(CONF_ICON)
                )
            )
        else:
            _LOGGER.debug("Address '%s' is not valid IP or MAC", address)

    if not switches:
        _LOGGER.error("No devices added")
        return False

    add_devices(switches)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号