Link to home
Start Free TrialLog in
Avatar of Vorenus
Vorenus

asked on

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,
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Vorenus
Vorenus

ASKER

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.
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 :)
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============