# Copyright 2026 SigmaSRC, Inc. All Rights Reserved.

"""Gather script for Windows wireless info using COM extensions."""


import os
import logging
from win32com.client import GetObject

from sigma.gather import gathering

logger = logging.getLogger("gather.gather_winwirelessnic")

def Gather(collector):
    # write header to output
    table = collector.table("wirelessnic", ["iswireless", "nicname", "nicstatus"])
    try:
        found = False
        objItems = GetObject("WinMgMts://./root/cimv2").InstancesOf("Win32_NetworkAdapterConfiguration")
        for item in objItems:
            caption = item.Properties_("Caption").Value
            id = item.Properties_("SettingID").Value

            # XXX Looking for wireless word in the description is not very good
            # but so far this is the only way that is working
            lcaption = caption.lower()
            if "wireless" in lcaption or "wlan" in lcaption:
                found = True
                active = id in gathering.get_active_interfaces()
                table.add(("1", caption, gathering.boolean_to_active(active)))
        if not found:
            table.add(("0", "", ""))
    except:
        logger.exception("winwirelessnic gather failed")

def _test():
    from sigma.gather import gathering
    gathering.test(Gather)

if __name__ == "__main__":
    _test()
