Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- ::
- :: Description: Changes MAC address of wireless extender via HTTP
- ::
- :: 2013.08.12 - WRC - Original.
- ::
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- @ECHO OFF
- setlocal
- set TIMEOUT=120
- :: Above sets how long to wait between cycles.
- set EXT_IP=192.168.10.1
- :: Above s IP address of Wireless extender
- set USER=admin
- :: Above sets username of Wireless extender
- set PASS=password
- :: Above sets password of Wireless extender
- set NICDEV_ID=
- :: Above sets device id of NIC
- :: Use devcon to determine what to set this to.
- :: This is used to disable and enable the NIC connected to the wireless extender after the MAC of it is changed.
- :: see below URL for use of this command http://blog.thilina.org/2011/06/enabledisable-lan-interface-by-command.html
- set CURL=c:\x\curl.exe
- :: Above sets location of curl.exe
- :: This batch uses curl to talk to the wireless extender via HTTP
- :: See http://curl.haxx.se/ for more info about curl and to download it
- set DEVCON=c:\x\devcon.exe
- :: Above sets location of devcon.exe
- :: Download devcon.exe here: http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe
- set CHOICE=c:\x\choice.exe
- :: Above sets location of choice.exe
- :: Get choice here: http://winsupport.org/utilities/freedos-choice.html
- set MACLIST=%1
- :: Above sets location of the list of macs you want to cycle through.
- :: %1 means you have to specify it when you run the file.
- :: %1 can be changed to a specific path and file.
- :: The format of this file is a list of MAC addresses, one per line with no spaces or colons.
- :: Each MAC should be 12 characters long.
- IF [%NICDEV_ID%] == [] GOTO :NONICDEV_ID
- IF NOT EXIST %SystemRoot%\system32\findstr.exe GOTO :NOFINDSTR
- IF NOT EXIST %CURL% GOTO :NOCURL
- IF NOT EXIST %DEVCON% GOTO :NODEVCON
- IF NOT EXIST %CHOICE% GOTO :NOCHOICE
- IF [%MACLIST%] == [] GOTO :NOMACLIST1
- IF NOT EXIST %MACLIST% GOTO :NOMACLIST2
- for /f "tokens=1" %%G IN (%MACLIST%) DO (call :WORK %%G)
- GOTO END
- :WORK
- :: This part of the batch will talk to the wireless extender via HTTP
- :: I found with my extender that things need to happen in a certain order
- :: or else access will be denied. That's why there is more going
- :: on here than just sending the change MAC address command.
- ECHO Attempting to setting MAC Address of Extender to %1
- ECHO Accessing Extender via HTTP...
- %CURL% -s -u %USER%:%PASS% http://%EXT_IP%/home.asp >%temp%\macx.tmp
- :: The above opens the home page of the Wireless Extender.
- findstr /c:"Wireless-N Router Webserver" %temp%\macx.tmp > NUL
- :: The above checks for the above string in the data returned from the wireless extender.
- if %errorlevel% == 0 ECHO Success!
- if %errorlevel% == 1 ECHO Failed! Trying again...
- if %errorlevel% == 1 GOTO :WORK
- ECHO Accessing LAN Settings via HTTP...
- %CURL% -s -u %USER%:%PASS% http://%EXT_IP%/tcpiplan.asp >%temp%\macx.tmp
- :: The above opens the tcpip configuration of the Wireless Extender.
- findstr /c:"LAN Interface Setup" %temp%\macx.tmp > NUL
- :: The above checks for the above string in the data returned from the wireless extender.
- if %errorlevel% == 0 ECHO Success!
- if %errorlevel% == 1 ECHO Failed! Trying again...
- if %errorlevel% == 1 GOTO :WORK
- ECHO Changing MAC Address of Extender to %1 via HTTP...
- %CURL% -s -u %USER%:%PASS% -d "lan_macAddr=%1&save=Apply+Changes&submit-url=%2Ftcpiplan.asp" http://%EXT_IP%/goform/formTcpipSetup >%temp%\macx.tmp
- :: The above sends the change MAC Address command to the Wireless Extender.
- findstr /c:"Change setting successfully!" %temp%\macx.tmp > NUL
- :: The above checks for the above string in the data returned from the wireless extender.
- if %errorlevel% == 0 ECHO Success!
- if %errorlevel% == 1 ECHO Failed! Trying again...
- if %errorlevel% == 1 GOTO :WORK
- ECHO Sending Reboot Command to Extender via HTTP...
- %CURL% -s -u %USER%:%PASS% -d "submit-url=%2Fstatus.asp" http://%EXT_IP%/goform/formRebootCheck >%temp%\macx.tmp
- :: The above sends the reboot command to the Wireless Extender.
- findstr /c:"This document has moved" %temp%\macx.tmp > NUL
- :: The above checks for the above string in the data returned from the wireless extender.
- if %errorlevel% == 0 ECHO Success!
- if %errorlevel% == 1 ECHO Failed! Trying again...
- if %errorlevel% == 1 GOTO :WORK
- ECHO Disabling NIC...
- %DEVCON% disable *%NICDEV_ID%*
- :: The above disables the NIC used to communicate with the wireless extender.
- :: Disabling and re-enabling the NIC to ensures the NIC can talk to the wireless extender
- :: after the MAC of the wireless extender has changed.
- ECHO Enabling NIC...
- %DEVCON% enable *%NICDEV_ID%*
- :: The above enables the NIC used to communicate with the wireless extender.
- ECHO Waiting %TIMEOUT% seconds...
- %CHOICE% /N /C Y /T %TIMEOUT% /D Y >NUL
- :: The above is the command that makes the batch wait before moving onto the next entry in the MAC list.
- GOTO :EOF
- :NONICDEV_ID
- ECHO NICDEV_ID not defined; aborting!
- GOTO :EOF
- :NOFINDSTR
- ECHO Findstr.exe not found; aborting!
- GOTO :EOF
- :NOCURL
- ECHO %CURL% not found; aborting!
- GOTO :EOF
- :NODEVCON
- ECHO %DEVCON% not found; aborting!
- GOTO :EOF
- :NOCHOICE
- ECHO %CHOICE% not found; aborting!
- GOTO :EOF
- :NOMACLIST1
- ECHO No MAC List provided; aborting!
- GOTO :EOF
- :NOMACLIST2
- ECHO MAC List (%MACLIST%) not found; aborting!
- GOTO :EOF
- :END
- ECHO Done!
- endlocal
- GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment