[RESOLVED] wmi_info & remote commands

Share here your tips or issues concerning WAPT Console or WAPT Agent / Venez ici partager vos problèmes et astuces concernants la console et l'agent WAPT
Règles du forum
Règles du forum communautaire
* English support on www.reddit.com/r/wapt
* Le support communautaire en français se fait sur ce forum
* Merci de préfixer le titre du topic par [RESOLU] s'il est résolu.
* Merci de ne pas modifier un topic qui est taggé [RESOLU]. Ouvrez un nouveau topic en référençant l'ancien
* Préciser version de WAPT installée, version complète ET numéro de build (2.2.1.11957 / 2.2.2.12337 / etc.) AINSI QUE l'édition Enterprise / Discovery
* Les versions 1.8.2 et antérieures ne sont plus maintenues. Les seules questions acceptées vis à vis de la version 1.8.2 sont liés à la mise à jour vers une version supportée (2.1, 2.2, etc.)
* Préciser OS du serveur (Linux / Windows) et version (Debian Buster/Bullseye - CentOS 7 - Windows Server 2012/2016/2019)
* Préciser OS de la machine d'administration/création des paquets et de la machine avec l'agent qui pose problème le cas échéant (Windows 7 / 10 / 11 / Debian 11 / etc.)
* Eviter de poser plusieurs questions lors de l'ouverture de topic, sinon il risque d'être ignorer. Si plusieurs sujet, ouvrir plusieurs topic, et de préférence les uns après les autres et pas tous en même temps (ie ne pas spammer le forum).
* Inclure directement les morceaux de code, les captures d'écran et autres images directement dans le post. Les liens vers les pastebin, les bitly et autres sites tierces seront systématiquement supprimés.
* Comme tout forum communautaire, le support est fait bénévolement par les membres. Si vous avez besoin d'un support commercial, vous pouvez contacter le service commercial Tranquil IT au 02.40.97.57.55
empbilly
Messages : 79
Inscription : 15 janv. 2018 - 20:59

23 mars 2018 - 17:56

Hi folks,

How can I declare the wmi_filter option? Can it be as below?

Code : Tout sélectionner

wmi_info(keys=['Win32_NetworkAdapter'])['name']['index']
Dernière modification par empbilly le 26 mars 2018 - 21:28, modifié 1 fois.
Avatar de l’utilisateur
dcardon
Expert WAPT
Messages : 1377
Inscription : 18 juin 2014 - 09:58
Localisation : Saint Sébastien sur Loire
Contact :

23 mars 2018 - 19:17

Hi Empbilly,
empbilly a écrit : 23 mars 2018 - 17:56 Hi folks,

How can I declare the wmi_filter option? Can it be as below?

Code : Tout sélectionner

wmi_info(keys=['Win32_NetworkAdapter'])['name']['index']
wmi_info gives out a data structure out of wmi module. You can just print the data structure or its inner parts:

Code : Tout sélectionner

wmi_data = wmi_info(keys=['Win32_NetworkAdapter'])['Win32_NetworkAdapter']
print wmi_data
print(wmi_data[0].keys())
for item in wmi_data:
    print item['Caption']


Cheers,

Denis
Denis Cardon - Tranquil IT
Communiquez autour de vous sur WAPT! Envoyez nous vos url de blog et d'articles dans la catégorie votre avis du forum, nous les mettrons en avant sur le site WAPT
empbilly
Messages : 79
Inscription : 15 janv. 2018 - 20:59

23 mars 2018 - 20:45

From the example above, I could make a script that disable via wapt, for example a computer wireless card?
Avatar de l’utilisateur
dcardon
Expert WAPT
Messages : 1377
Inscription : 18 juin 2014 - 09:58
Localisation : Saint Sébastien sur Loire
Contact :

24 mars 2018 - 23:33

Hi empbilly,
empbilly a écrit : 23 mars 2018 - 20:45 From the example above, I could make a script that disable via wapt, for example a computer wireless card?
wmi_info() just give out a python list/dict datastructure with information for inventory. You cannot do any action out of that wmi_info() function. However you can import wmi python module and use it in your script.

Regarding the specific subject of your question, if you have the name of the interface, then you could use netsh with something like:

Code : Tout sélectionner

netsh interface set interface "network_adapter_name" admin=disable
But it is not always easy to get the network_adapter_name right, especially if your Windows is not an English one and has accent in the name...

Cheers,

Denis
Denis Cardon - Tranquil IT
Communiquez autour de vous sur WAPT! Envoyez nous vos url de blog et d'articles dans la catégorie votre avis du forum, nous les mettrons en avant sur le site WAPT
empbilly
Messages : 79
Inscription : 15 janv. 2018 - 20:59

26 mars 2018 - 19:46

Okay. I'm trying to make the script below work. The problem is the accent on the text "Conexão local 2" that the "con" variable receives. I tried several ways to decode and encode to utf-8, but without success.

>>> con = 'Conexão local 2'.decode('utf-8')
>>> print con
Conexão local 2
>>> con
u'Conex\xe3o local 2'
>>>

How can I solve this problem?

Code : Tout sélectionner

# -*- coding: utf-8 -*-
from setuphelpers import *
import subprocess

uninstallkey = []

con = 'Conexão local 2'

def install():
    print "Instalando Wi-fi adapter disable"
    try:
        x = subprocess.Popen(["cmd.exe", "/c", "wmic path win32_networkadapter where NetConnectionID='%s' call disable" % (con)], stdout=subprocess.PIPE, shell=True)
        print (x.stdout.read())
    except (RuntimeError, TypeError, NameError):
        print "Erro na execução do cmd.exe"
empbilly
Messages : 79
Inscription : 15 janv. 2018 - 20:59

26 mars 2018 - 21:27

Now, it's works!!! :D

Code : Tout sélectionner

# -*- coding: UTF-8 -*-
from setuphelpers import *
import subprocess
import locale

uninstallkey = []

con = u'Conexão de Rede sem Fio'

def install():
    print u"Exercutando Wi-fi card disable"
    try:
        x = subprocess.Popen(["cmd.exe", "/c", "wmic path win32_networkadapter where NetConnectionID='%s' call disable" % (con.encode(locale.getpreferredencoding()))], stdout=subprocess.PIPE, shell=True)
        print (x.stdout.read())
    except (RuntimeError, TypeError, NameError):
        print u"Erro na execução do cmd.exe"
Avatar de l’utilisateur
vcardon
Expert WAPT
Messages : 248
Inscription : 06 oct. 2017 - 22:55
Localisation : Nantes, FR

26 mars 2018 - 21:34

Hello Empbilly,

I see portuguese comments in your script to disable wifi connexions, are you writing from Brazil ?

If that's the case, that would be just cool to start having WAPT in South America.

If your language is Portuguese, do you feel it would be useful to have WAPT internationalized in Portuguese, or do you feel that adminsys are sufficiently familiar with English where you live ?

Thanks.

Vincent
Vincent CARDON
Tranquil IT
empbilly
Messages : 79
Inscription : 15 janv. 2018 - 20:59

27 mars 2018 - 02:14

I see portuguese comments in your script to disable wifi connexions, are you writing from Brazil ?
Yes. I live in Brazil and work in an education institution.

If that's the case, that would be just cool to start having WAPT in South America.
:D

If your language is Portuguese, do you feel it would be useful to have WAPT internationalized in Portuguese, or do you feel that adminsys are sufficiently familiar with English where you live ?
I think it would be great to have, mainly, the wapt documentation in Portuguese. Speaking of the sysadmins of our institution as a whole, more or less about 20 campus, the vast majority do not have an intermediary to advanced skills in English.
Verrouillé