Ejemplo n.º 1
0
def get_interface_info(_fd, iface):
    log = logger()
    from xpra.platform.win32.comtypes_util import QuietenLogging
    with QuietenLogging():
        try:
            from comtypes import CoInitialize  #@UnresolvedImport
            CoInitialize()
            from comtypes.client import CreateObject  #@UnresolvedImport
            o = CreateObject("WbemScripting.SWbemLocator")
            s = o.ConnectServer(".", "root\\cimv2")
            query = "SELECT * FROM Win32_NetworkAdapter WHERE GUID='%s'" % iface
            res = s.ExecQuery(query)
            log("ExecQuery(%s) returned %i rows", query, res.Count)
            if res.Count == 1:
                for r in res:
                    props = {}
                    for k, ik, conv in (
                        ("AdapterType", "adapter-type", str),
                        ("Caption", "caption", str),
                        ("Description", "description", str),
                        ("DeviceID", "id", int),
                        ("GUID", "GUID", str),
                        ("Index", "index", int),
                        ("Name", "name", str),
                        ("ProductName", "product-name", str),
                        ("Speed", "speed", int),
                    ):
                        try:
                            v = conv(r.Properties_[k].Value)
                        except Exception as e:
                            log.error(
                                "Error retrieving '%s' from network adapter record:",
                                k)
                            log.error(" %s", e)
                        else:
                            props[ik] = v
                    log("get_interface_info(%s)=%s" % (iface, props))
                    return props
        except Exception as e:
            log("get_interface_info(%s)", iface, exc_info=True)
            from xpra.util import first_time
            if first_time("win32-network-query"):
                log.error("Error: failed to query network interface:")
                log.error(" %s", e)
        return {}