Python/Python for Windows

[Python] subprocess를 이용한 윈도우 방화벽 ON/OFF 점검

Pydole 2020. 1. 28. 19:23

 

 시스템 관리를 하다 윈도우 방화벽 상태를 주기적으로 체크해야 할 일이 있어서 간단히 파이썬과 명령어를 조합하여

만들어 보았다.

 


 

 

subprocess.check_output : 명령어 결과를 문자열로 리턴 받음

 

import subprocess

if 'ON' in str(subprocess.check_output(['netsh', 'advfirewall', 'show', 'currentprofile', 'state'], universal_newlines=True)):
    print('Windows Firewall State ON')
    
else:
    print('Windows Firewall State OFF')

 

 

 

RESULT : Windows Firewall State ON

 

 

 

 

RESULT : Windows Firewall State OFF