Getting information of firewall status

Just starting out? Need help? Post your questions and find answers here.
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Getting information of firewall status

Post by boyoss »

I'm looking for a solution to get information of the firewall. There is a cmd command

Code: Select all

netsh advfirewall show currentprofile state
But the answer is in the language of the computer, and i want to make a software that will run on all languages.

Any ideas how to fix this problem?
The best will be an api getting information from the firewall (and settings rules) but i don't think it exist.

Thanks

Edit: ok i found this, but i have no idea how to convert it to purebasic
https://msdn.microsoft.com/en-us/librar ... s.85).aspx

__________________________________________________
URL tags added
14.03.2017
RSBasic
User avatar
bbanelli
Enthusiast
Enthusiast
Posts: 544
Joined: Tue May 28, 2013 10:51 pm
Location: Europe
Contact:

Re: Getting information of firewall status

Post by bbanelli »

boyoss wrote:I'm looking for a solution to get information of the firewall. There is a cmd command

Code: Select all

netsh advfirewall show currentprofile state
But the answer is in the language of the computer, and i want to make a software that will run on all languages.

Any ideas how to fix this problem?
The best will be an api getting information from the firewall (and settings rules) but i don't think it exist.

Thanks

Edit: ok i found this, but i have no idea how to convert it to purebasic
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Maybe this will help?

Code: Select all

EnableExplicit

DeclareModule Security
  EnumerationBinary WSC_SECURITY_PROVIDER
    #WSC_SECURITY_PROVIDER_FIREWALL
    #WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS
    #WSC_SECURITY_PROVIDER_ANTIVIRUS
    #WSC_SECURITY_PROVIDER_ANTISPYWARE
    #WSC_SECURITY_PROVIDER_INTERNET_SETTINGS 
    #WSC_SECURITY_PROVIDER_USER_ACCOUNT_CONTROL
    #WSC_SECURITY_PROVIDER_SERVICE
  EndEnumeration
  
  Enumeration WSC_SECURITY_PROVIDER_HEALTH
    #WSC_SECURITY_PROVIDER_HEALTH_GOOD
    #WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED
    #WSC_SECURITY_PROVIDER_HEALTH_POOR
    #WSC_SECURITY_PROVIDER_HEALTH_SNOOZE
  EndEnumeration
  
  Structure Security
    Firewall.i
    FirewallState.s
    Update.i
    UpdateState.s
    AntiVirus.i
    AntiVirusState.s
    AntiSpyware.i
    AntiSpywareState.s
    Internet.i
    InternetState.s
    UAC.i
    UACState.s
    WSC.i
    WSCState.s
  EndStructure
  
  Define.i SecurityLib, pHealth
  Define Security.Security
  
  Prototype.i WscGetSecurityProviderHealth(Providers.i, pHealth.i)
  SecurityLib = OpenLibrary(#PB_Any, "Wscapi.dll")
  If SecurityLib
    Global.i WscGetSecurityProviderHealth : WscGetSecurityProviderHealth.WscGetSecurityProviderHealth = GetFunction(SecurityLib, "WscGetSecurityProviderHealth")
  EndIf
  
  Declare GetSecurityState()
  Declare.s Parse(pHealth.i)
EndDeclareModule
Module Security
  Procedure GetSecurityState()
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_FIREWALL, Security::@pHealth)
    Security::Security\Firewall = Security::pHealth
    Security::Security\FirewallState = Security::Parse(Security::pHealth)
    
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, Security::@pHealth)
    Security::Security\Update = Security::pHealth
    Security::Security\UpdateState = Security::Parse(Security::pHealth)
    
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_ANTIVIRUS, Security::@pHealth)
    Security::Security\AntiVirus = Security::pHealth
    Security::Security\AntiVirusState = Security::Parse(Security::pHealth)
    
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_ANTISPYWARE, Security::@pHealth)
    Security::Security\AntiSpyware = Security::pHealth
    Security::Security\AntiSpywareState = Security::Parse(Security::pHealth)
    
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_USER_ACCOUNT_CONTROL, Security::@pHealth)
    Security::Security\UAC = Security::pHealth
    Security::Security\UACState = Security::Parse(Security::pHealth)
    
    Security::WscGetSecurityProviderHealth(Security::#WSC_SECURITY_PROVIDER_SERVICE, Security::@pHealth)
    Security::Security\WSC = Security::pHealth
    Security::Security\WSCState = Security::Parse(Security::pHealth)
    
    ProcedureReturn
  EndProcedure
  Procedure.s Parse(pHealth.i)
    Protected Status.s
    Select pHealth
      Case 0
        Status = "The status of the security provider category is good and does not need user attention."
      Case 1
        Status = "The status of the security provider category is not monitored by WSC."
      Case 2
        Status = "The status of the security provider category is poor and the computer may be at risk."
      Case 3
        Status = "The security provider category is in snooze state. Snooze indicates that WSC is not actively protecting the computer."
    EndSelect
    ProcedureReturn Status
  EndProcedure
EndModule

DisableExplicit
Call it like this Security::GetSecurityState() and you will get desired states.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
https://www.pci-z.com/
boyoss
User
User
Posts: 81
Joined: Fri Feb 05, 2016 10:11 am

Re: Getting information of firewall status

Post by boyoss »

thanks it's very sweet, but i need details about the firewall and the rules.
novablue
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Nov 27, 2016 6:38 am

Re: Getting information of firewall status

Post by novablue »

I also would like to know an answer to this.
Post Reply