• Welcome, Guest. Please login.
 
September 23, 2020, 12:54:18 am

News:

Welcome to the SQLitening support forums!


Firewall on/off source code

Started by cj, December 09, 2012, 11:36:01 am

Previous topic - Next topic

cj

December 09, 2012, 11:36:01 am Last Edit: December 09, 2012, 11:48:18 am by cj
Here is an updated version of turning firewall on/off using Windows 7
The turn on code shows the window in green.  The turn off in red.
This using the /T and /K options of command processor to see results in the command window.
This can be eliminated by  SHELL ShellStatement instead of SHELL StayAtCommandPrompt  + ShellStatement.

Based on firewall comands at:
http://www.windowsitpro.com/article/windows-server/windows-firewall-netsh-commands-142324




FUNCTION PBMAIN () AS LONG
  FirewallON  "SQLitening", 51234
  FirewallOFF "SQLitening", 51234
END FUNCTION 

FUNCTION FirewallOn(BYVAL sRuleName AS STRING, PortNumber AS LONG) AS LONG
  LOCAL StayAtCommandPrompt AS STRING
  StayAtCommandPrompt = ENVIRON$("COMSPEC") + " /T:2F /K " 'white on green background
  LOCAL ShellStatement AS STRING
  ShellStatement = "netsh advfirewall firewall add rule name=""*RULENAME*"" dir=in action=allow protocol=TCP localport=*PORTNUMBER*
  REPLACE "*RULENAME*"   WITH sRuleName           IN ShellStatement
  REPLACE "*PORTNUMBER*" WITH FORMAT$(PortNumber) IN ShellStatement
  SHELL StayAtCommandPrompt +  ShellStatement    'optional, wait for results
  'SHELL ShellStatement                           'or just do it
END FUNCTION

FUNCTION FirewallOff(BYVAL sRuleName AS STRING, PortNumber AS LONG) AS LONG
  LOCAL StayAtCommandPrompt AS STRING
  LOCAL ShellStatement AS STRING
  StayAtCommandPrompt = ENVIRON$("COMSPEC") + " /T:4F /K" 'yellow on red background
  ShellStatement = "netsh advfirewall firewall delete rule name=""*RULENAME*"" protocol=TCP localport=*PORTNUMBER*"
  REPLACE "*RULENAME*"   WITH sRuleName           IN ShellStatement
  REPLACE "*PORTNUMBER*" WITH FORMAT$(PortNumber) IN ShellStatement
  SHELL StayAtCommandPrompt + ShellStatement      'optional, wait for results
  'SHELL ShellStatement                            'or just do it
END FUNCTION

Fredrick Ughimi

Hello CJ,

Thank your codes and the link. Useful

Useful info in there.
Fredrick O. Ughimi<br /><br />fughimi@gmail.com<br />- Freedom lies in being bold -- Robert Frost, Poet