kanazux / wmi-query

Converte wmi queries to default dict
BSD 2-Clause "Simplified" License
0 stars 1 forks source link

Connection Hanging forever when RPC Service is not available at target system #2

Open m0ellemeister opened 5 years ago

m0ellemeister commented 5 years ago

When the WMI Response is: "Name or service not known" caused by RPC Service is not available (e.g. System to be queried is under heavy load) the connection to this particular system will hang infinitely. The issue in such a circumstance is, that the connection won't be closed as expected.

I fixed this by adding finally: in wmi_conn.py to the try: + except:block:

[...]   
   try:
        while True:
            _list_wmi_data.append(_iwb_class_object.Next(0xffffffff, 1)[0])
    except DCERPCException:
        pass
    finally:
        _iwb_nt_login.RemRelease()
        _dcom.disconnect()
[...]

That way, the _dcom.disconnect() will be executed no matter what.