本文主要是介绍Python 获取防火墙策略并保存为TXT文档,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
from winreg import EnumValue, CloseKey, OpenKey,HKEY_LOCAL_MACHINE
def firewallRules():
key = OpenKey(HKEY_LOCAL_MACHINE,\
r"SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules")
i = 0
with open('firewallRules.txt', mode='at', encoding='utf-8') as f:
while True:
try:
name,value, t = EnumValue(key,i)
f.write(name+' '+value+'\n')
i=i+1
except WindowsError:
break
CloseKey(HKEY_LOCAL_MACHINE)
return None
firewallRules()
这篇关于Python 获取防火墙策略并保存为TXT文档的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!