您可以使用此命令仅获取公用配置文件的状态:
“netsh advfirewall显示公共状态”
此命令可与子流程模块一起在python脚本中使用:
result = subprocess.check_output(["netsh", "advfirewall", "show ", "allprofiles", "state"].decode('utf-8')
结果将是一个字符串,使用regex可以从中获取值。
https://docs.python.org/3/library/re.html
regex示例:
status = re.search('state[ ]*([A-Za-z])*', result).group(1)