Enable\Disable "Allow incoming Echo request" in the windows firewall

I would like to enable the "Allow incoming Echo request" when my users are on our corporate network as they will be protected by our newtork. But I would like it disabled when they using ADSL off our network. Is it possible to do this and how?
ITZUGAsked:
Who is Participating?
 
anil_uConnect With a Mentor Commented:
Hi

Try the following script, open notepad, copy and paste the script below into notepad, save as icmp.vbs, open command prompt and run from the directory you save icmp.vbs the following command
cscript icmp.vbs

This script takes the network name which is a variable strConnectionName which you need to change and on the computer that is run, checks to see if that nic is connected
"objItem.NetConnectionStatus = 2"
and if so, displays name, mac address and description. It then enable the echo request if its disabled. If its disabled, it enables it.
The script is commented, well a little bit :) but you should be able to amend it

The idea is that this script could be part of log on/off script which when run, does the check and enables it if required.


-----------------------
strConnectionName = "Wireless Network Connection"

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter")

For Each objItem in colItems


If objItem.NetConnectionStatus = 2 Then      'If connected then...
      If objItem.NetConnectionID = strConnectionName Then      'The connected to the required network then...
                Wscript.Echo "Name: " & objItem.Name      'Show details
                Wscript.Echo "Description: " & objItem.Description            'Show details
                Wscript.Echo "MAC Address: " & objItem.MACAddress            'Show details

                  'Modify firewall
                  Set objFirewall = CreateObject("HNetCfg.FwMgr")
                  Set objPolicy = objFirewall.LocalPolicy.CurrentProfile
                  Set objICMPSettings = objPolicy.ICMPSettings
                  
                  'Enable ICMP Allow incomming echo request if disabled otherwise disable
                  If objICMPSettings.AllowRedirect = FALSE Then
                        objICMPSettings.AllowInboundEchoRequest = TRUE
                  Else
                        objICMPSettings.AllowInboundEchoRequest = FALSE
                  End If

      End If
End IF

Next

-------------------------------------
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.