Answer the question
In order to leave comments, you need to log in
How to open and close ports through Python?
There is a PowerShell script for closing ports, is it possible to make the same script but in python?
I saw that it is possible to call PS commands through python, but this is not quite what I need
. This is what the script looks like in PowerShell:
Answer the question
In order to leave comments, you need to log in
The module import os
has a method system()
that sends commands to the shell.
import os
request = ('...') # здесь код для открытия или закрытия портов
code = os.system(request)
print(code) # если выводит 0 - то успешно
due to my dull pythonic knowledge, I did not find how to directly control the firewall from python (you can, like, turn it on / off completely via wmi). however, to remove one level of abstraction, you can run not powershell commands from python, but netsh commands. and they can already steer the firewall as you like.
https://stackoverflow.com/questions/12381733/how-t... by the
way, if it's a matter of powershell cross-platform, then powershell core runs well on all sorts of linuxes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question