Failing to connect to a host with WMI - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Failing to connect to a host with WMI (/thread-34435.html) |
Failing to connect to a host with WMI - tester_V - Jul-31-2021 Happy Friday! I think I managed to install "WMI" module. When I use: import wmiMy script does not error out. The remote host is online, I used the admin username and pass. Script: try: connection = wmi.WMI('245.234.44.56', user="Some_User", password="password") print("connection is established") except: print("connection failed") I'm wondering if Python has everything installed to make the connection...Thank you. RE: Failing to connect to a host with WMI - Larz60+ - Jul-31-2021 It looks like the connection was refused by the site. The code seems OK. check your pwd,, etc. RE: Failing to connect to a host with WMI - tester_V - Jul-31-2021 I do not understand why it did not work. I tried different snippet and this one works: import wmi ip = '101.17.48.11' username = 'Some_user' password = 'somepassword' from socket import * try: print("Establishing connection to %s" %ip) connection = wmi.WMI(ip, user=username, password=password) print("Connection established") except wmi.x_wmi: print("Your Username and Password of "+getfqdn(ip)+" are wrong.")I'd like to get a processes list of the remote host I just connected . Should I make a batch file and make a 'call' to run it or call the Power shell? What is a proper way to do this? Thank you. RE: Failing to connect to a host with WMI - tester_V - Aug-03-2021 Hi, What about starting a batch file on a remote host? I can copy a batch file to read the processes of a Host. Does anyone know what is the command for that? I cannot find anything useful on how to do that. Thank you. RE: Failing to connect to a host with WMI - tester_V - Aug-03-2021 Well, I was looking for an example for a few days and just found it. Plugged it in ad it works! here is the whole snipped if anyone is interested: import wmi from socket import * ip = '101.17.48.11' username = 'Some_user' password = 'somepassword' proc=open('c:\\somedir','w') try: print("Establishing connection to %s" %ip) connection = wmi.WMI(ip, user=username, password=password) connection = wmi.WMI(ip) print("Connection established") for process in connection.Win32_Process(): #print("ID: {0}\nProcessName: {1}\n".format(process.ProcessId,process.Name)) print(f"Proccess-ID/Nmae -> {process.ProcessId} - {process.Name} ") proc.write(str(process.ProcessId)+","+process.Name+"\n") except wmi.x_wmi: print("Your Username and Password of "+getfqdn(ip)+" are wrong.") proc.close()Thank you everyone for the support and coaching! I think this is the best place to learn Python. RE: Failing to connect to a host with WMI - Larz60+ - Aug-04-2021 Some where along the line, you changed IP addresses, first attempt shows 245.234.44.56 The one that works shows: 101.17.48.11 RE: Failing to connect to a host with WMI - tester_V - Aug-10-2021 (Aug-04-2021, 01:27 AM)Larz60+ Wrote: Some where along the line, you changed IP addresses, first attempt shows 245.234.44.56 it is not real IP it was just an example. I'm ok now. THank you! |