Quick DOS batch file to turn on or off the Windows firewall.

Add Comment | Nov 01, 2010

Another quick post!

I am a frequent traveler, and as such I like to be able to turn on (or off) my Windows firewall quickly.  The Windows firewall in Windows XP isn't perfect, but I would suggest using it or something else whenever connecting to public WIFI. 

Here is the script I use, which simply prompts you if you want your firewall on or off and uses NETSH to accomplish the task:

@echo off
color 0a
cls
:local_question
echo.
echo Do you want to enable or disable the firewall?
echo.
echo           ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»  ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo           º A. Enable       º  º B. Disable      º            
echo           ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ  ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
echo.
set localchoice=
set /p localchoice= Press A for enable or B for disable:
if not '%localchoice%'=='' set finalchoice=%finalchoice:~0,1%
if '%localchoice%'=='A' goto start
if '%localchoice%'=='a' goto start
if '%localchoice%'=='B' goto stop
if '%localchoice%'=='b' goto stop
@ECHO.
@ECHO "%localchoice%" is not valid please try again
goto local_question

:stop

netsh firewall set opmode disable
goto end

:start
netsh firewall set opmode enable
goto end

:end
echo The End.
ping 127.0.0.1 > nul
exit

 

Have a good start to November!

-Derek

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Using netsh to script IP changes.

Add Comment | Sep 15, 2010

Greetings!  Short one today.  Over the last week I have had to change a set of IP addresses for a new project repeatedly.

To save time I decided to quickly make a batch script to do it for me!  The premise is that there are two computers being used for a specific task and are connecting to a real time emulator.  The software being designed assumes that whatever computer it is on the local IP address is always the same (192.168.1.2).

 

The users simply have to double click on the batch file to set the IP, or when they're done they double click on a second batch file to reset the network connection back to dynamically allocated (dhcp).

 

Batch script one:

netsh int ip set address name = "Local Area Connection" source = static addr = 192.168.1.2 mask = 255.255.255.0

Batch script two:

netsh interface ip set address name "Local Area Connection" dhcp

 

Very short, very simple, but saves me a ton of time!  That's all for now!

Thanks,

Derek

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Secure wipe of a hard drive using WinPE.

Add Comment | Jun 02, 2010

 

 

The wiping of a hard drive is typically seen as fairly trivial.  There are tons of applications out there that will do it for you.  Point-->Click-->Global-Thermo Nuclear War.

However, these applications are typically expensive or unreliable.  Plus, if you have a laptop or lack a secondary computer to put the hard drive into – how on earth do you wipe it quickly and easily while still conforming to a 7 pass rule (this means that every possible bit on the hard drive is set to 0 and then to 1 seven times in a row)?  Yes, one pass should be enough – as turning every bit from a 1 to a zero will wipe the data from existence.  But, we’re dealing with tinfoil hat wearing types here people.  DOD standards dictate at least 3 passes, and typically 7 is the preferred amount.  I’m not going to argue about data recovery.  I have been told to use 7 passes, and so I will.  So say we all!

Quite some time ago I used to make a BartPE XP-based boot cd for the original purpose of securely wiping data.  I loved BartPE and integrated so many plugins into my builds that I could do pretty much anything directly from CD.  Reset passwords, uninstall security updates, wipe drives, chkdsk, remove spyware, install Windows, etc.  However, with the newer multi-core systems and new chipsets coming out from vendors, I found that BartPE was rather difficult to keep up to date. 

I have since switched to WinPE 3.0 (Windows Preinstallation Environment). http://technet.microsoft.com/en-us/library/cc748933(WS.10).aspx

 It is fairly simple to create your own CD, and I have made a few helpful scripts to easily integrate drivers and rebuild the ISO file for you.  I’ll cover making your own boot CD utilizing WinPE 3.0 in a later post – I can talk about WinPE forever and need to collect my thoughts!!  My wife loves talking about WinPE almost as much as talking about Doctor Who.  Wait, did I say loves?  Hmmmm, I may have meant loathes.

The topic at hand?  Right. Wiping a drive! I must have drunk too much coffee this morning.  I like to use a simple batch script that calls a combination of diskpart.exe from Microsoft® and Sdelete.exe created by our friend Mark Russinovich. http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx

All of the following files are located within the same directory on my WinPE boot CD.

Here are the contents of wipe_me.bat, script.txt and sdelete.reg.

Wipe_me.bat:

 

@echo off
echo.
echo     I will completely wipe the local hard drives using
echo     7 individual wipes. The data will NOT
echo     be recoverable.  I will begin after you
pause
echo.
echo Preparing to partition and format disk.
Diskpart.exe /s "script.txt"
REM I was annoyed by not having a completely automated script – and Sdelete wants you to accept the license agreement. So, I added a registry file to skip doing that.
regedit /S sdelete.reg
rem sdelete options selected are: -p (passes) -c (zero free space) -s (recurse through subdirectories, if any) -z (clean free space) [drive letter]
sdelete.exe -p 7 -c -s -z c:
echo.
echo Pass seven complete.
echo.
echo Wiping complete.
Pause
exit
 

script.txt:

list disk
select disk 0
clean
create partition primary
select partition 1
active
format FS=NTFS LABEL="New Volume" QUICK
assign letter=c
exit

 

 *Notes: This script assumes one local hard drive – change the script as you see fit for your environment.  The clean command will overwrite the master boot record and any hidden sector information – so be careful!

sdelete.reg:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Sysinternals\SDelete]

"EulaAccepted"=dword:00000001

 
With a combination of WinPE, sdelete.exe and your friendly neighborhood text editor you can begin wiping drives as quickly and easily as possible!  I hope this helps, I get asked this a lot in my line of work.

Best of luck,

Derek

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati