Windows Firewall Script

Hi,

Do somebody has a script or could tell me how I could script the WIndows Firewall to do only shut it down on LAN connections but let it switched on on RAS and Wireless ones ?

Thanks,
LVL 4
VorenusAsked:
Who is Participating?
 
Farhan KaziSystems EngineerCommented:
Greetings Vorenus,
You can use following statement to Enable or Disable Firewall on specific interface from command line.

Click Start -> Run -> Cmd.exe -> OK

NetSh FireWall Set OpMode Mode=ENABLE/ DISABLE Interface=<InterfaceNameHere>

:: You can make batch file like following to Enable and Disable Firewall for particular Interface .
@ECHO OFF
NetSh FireWall Set OpMode Mode=ENABLE Interface=WAN
NetSh FireWall Set OpMode Mode=DISABLE Interface=LAN
EXIT /B /0

Hope this helps!
Farhan
0
 
VorenusAuthor Commented:
Hi Farhan,

Thanks : it is a nice command.
That said, what I am ideally after is something even more generic, which means without knowing the name the of Interface, which may change from Windows' language or setups.

Ideally, it would even work for devices that the system do not know yet when the script is ran...
For example, if someday we plug an USB Ethernet Adapter, I would like the firewall to not be active on this device, that has never been plugged before.
In short, I would like the firewall to be always shutdown for LAN devices, currently plugged or plugged in the future.

I hope I make sense.
Thanks in advance.
0
 
Farhan KaziSystems EngineerCommented:
Know interface name is not a problem like if you goto to the command line paste following statement it will give you all interface names.

FOR /F "skip=2 tokens=4" %i IN ('NetSh Interface show interface') DO @ECHO %i

But the problem is how would system know which interface is a WAN interface??? One way it check default gateway or of all interface or to check routing table!! but it will become too complicated :)
0
 
Fatal_ExceptionSystems EngineerCommented:
I use a script to turn off and on my firewalls..  easy to do..

But, I have yet to find a way to have a script 'know' the difference between LAN and WAN, or any other interface...  just don't think there is a way to do it..

I even have a small app that I wrote in .NET that installs a toggle on / off for the firewall..  you can have it to by downloading it from my website..

http://65.25.157.6/doverpro.htm

============Copy / Paste============

Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

objPolicy.FirewallEnabled = True
============Copy / Paste============
Set objFirewall = CreateObject("HNetCfg.FwMgr")
Set objPolicy = objFirewall.LocalPolicy.CurrentProfile

objPolicy.FirewallEnabled = False

============Copy / Paste============

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.