Guest User

Batch to auto-change MAC of wifi extender

a guest
Aug 14th, 2013
1,952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. ::
  3. :: Description: Changes MAC address of wireless extender via HTTP
  4. ::
  5. :: 2013.08.12 - WRC - Original.
  6. ::
  7. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  8. @ECHO OFF
  9. setlocal
  10. set TIMEOUT=120
  11. :: Above sets how long to wait between cycles.
  12. set EXT_IP=192.168.10.1
  13. :: Above s IP address of Wireless extender
  14. set USER=admin
  15. :: Above sets username of Wireless extender
  16. set PASS=password
  17. :: Above sets password of Wireless extender
  18. set NICDEV_ID=
  19. :: Above sets device id of NIC
  20. :: Use devcon to determine what to set this to.
  21. :: This is used to disable and enable the NIC connected to the wireless extender after the MAC of it is changed.
  22. :: see below URL for use of this command http://blog.thilina.org/2011/06/enabledisable-lan-interface-by-command.html
  23. set CURL=c:\x\curl.exe
  24. :: Above sets location of curl.exe
  25. :: This batch uses curl to talk to the wireless extender via HTTP
  26. :: See http://curl.haxx.se/ for more info about curl and to download it
  27. set DEVCON=c:\x\devcon.exe
  28. :: Above sets location of devcon.exe
  29. :: Download devcon.exe here: http://download.microsoft.com/download/1/1/f/11f7dd10-272d-4cd2-896f-9ce67f3e0240/devcon.exe
  30. set CHOICE=c:\x\choice.exe
  31. :: Above sets location of choice.exe
  32. :: Get choice here: http://winsupport.org/utilities/freedos-choice.html
  33. set MACLIST=%1
  34. :: Above sets location of the list of macs you want to cycle through.
  35. :: %1 means you have to specify it when you run the file.
  36. :: %1 can be changed to a specific path and file.
  37. :: The format of this file is a list of MAC addresses, one per line with no spaces or colons.
  38. :: Each MAC should be 12 characters long.
  39.  
  40. IF [%NICDEV_ID%] == [] GOTO :NONICDEV_ID
  41. IF NOT EXIST %SystemRoot%\system32\findstr.exe GOTO :NOFINDSTR
  42. IF NOT EXIST %CURL% GOTO :NOCURL
  43. IF NOT EXIST %DEVCON% GOTO :NODEVCON
  44. IF NOT EXIST %CHOICE% GOTO :NOCHOICE
  45. IF [%MACLIST%] == [] GOTO :NOMACLIST1
  46. IF NOT EXIST %MACLIST% GOTO :NOMACLIST2
  47.  
  48.  
  49. for /f "tokens=1" %%G IN (%MACLIST%) DO (call :WORK %%G)
  50. GOTO END
  51.  
  52. :WORK
  53. :: This part of the batch will talk to the wireless extender via HTTP
  54. :: I found with my extender that things need to happen in a certain order
  55. :: or else access will be denied. That's why there is more going
  56. :: on here than just sending the change MAC address command.
  57.  
  58. ECHO Attempting to setting MAC Address of Extender to %1
  59. ECHO Accessing Extender via HTTP...
  60. %CURL% -s -u %USER%:%PASS% http://%EXT_IP%/home.asp >%temp%\macx.tmp
  61. :: The above opens the home page of the Wireless Extender.
  62. findstr /c:"Wireless-N Router Webserver" %temp%\macx.tmp > NUL
  63. :: The above checks for the above string in the data returned from the wireless extender.
  64. if %errorlevel% == 0 ECHO Success!
  65. if %errorlevel% == 1 ECHO Failed! Trying again...
  66. if %errorlevel% == 1 GOTO :WORK
  67.  
  68. ECHO Accessing LAN Settings via HTTP...
  69. %CURL% -s -u %USER%:%PASS% http://%EXT_IP%/tcpiplan.asp >%temp%\macx.tmp
  70. :: The above opens the tcpip configuration of the Wireless Extender.
  71. findstr /c:"LAN Interface Setup" %temp%\macx.tmp > NUL
  72. :: The above checks for the above string in the data returned from the wireless extender.
  73. if %errorlevel% == 0 ECHO Success!
  74. if %errorlevel% == 1 ECHO Failed! Trying again...
  75. if %errorlevel% == 1 GOTO :WORK
  76.  
  77. ECHO Changing MAC Address of Extender to %1 via HTTP...
  78. %CURL% -s -u %USER%:%PASS% -d "lan_macAddr=%1&save=Apply+Changes&submit-url=%2Ftcpiplan.asp" http://%EXT_IP%/goform/formTcpipSetup >%temp%\macx.tmp
  79. :: The above sends the change MAC Address command to the Wireless Extender.
  80. findstr /c:"Change setting successfully!" %temp%\macx.tmp > NUL
  81. :: The above checks for the above string in the data returned from the wireless extender.
  82. if %errorlevel% == 0 ECHO Success!
  83. if %errorlevel% == 1 ECHO Failed! Trying again...
  84. if %errorlevel% == 1 GOTO :WORK
  85.  
  86. ECHO Sending Reboot Command to Extender via HTTP...
  87. %CURL% -s -u %USER%:%PASS% -d "submit-url=%2Fstatus.asp" http://%EXT_IP%/goform/formRebootCheck >%temp%\macx.tmp
  88. :: The above sends the reboot command to the Wireless Extender.
  89. findstr /c:"This document has moved" %temp%\macx.tmp > NUL
  90. :: The above checks for the above string in the data returned from the wireless extender.
  91. if %errorlevel% == 0 ECHO Success!
  92. if %errorlevel% == 1 ECHO Failed! Trying again...
  93. if %errorlevel% == 1 GOTO :WORK
  94.  
  95. ECHO Disabling NIC...
  96. %DEVCON% disable *%NICDEV_ID%*
  97. :: The above disables the NIC used to communicate with the wireless extender.
  98. :: Disabling and re-enabling the NIC to ensures the NIC can talk to the wireless extender
  99. :: after the MAC of the wireless extender has changed.
  100.  
  101. ECHO Enabling NIC...
  102. %DEVCON% enable *%NICDEV_ID%*
  103. :: The above enables the NIC used to communicate with the wireless extender.
  104.  
  105. ECHO Waiting %TIMEOUT% seconds...
  106. %CHOICE% /N /C Y /T %TIMEOUT% /D Y >NUL
  107. :: The above is the command that makes the batch wait before moving onto the next entry in the MAC list.
  108.  
  109. GOTO :EOF
  110.  
  111. :NONICDEV_ID
  112. ECHO NICDEV_ID not defined; aborting!
  113. GOTO :EOF
  114.  
  115. :NOFINDSTR
  116. ECHO Findstr.exe not found; aborting!
  117. GOTO :EOF
  118.  
  119. :NOCURL
  120. ECHO %CURL% not found; aborting!
  121. GOTO :EOF
  122.  
  123. :NODEVCON
  124. ECHO %DEVCON% not found; aborting!
  125. GOTO :EOF
  126.  
  127. :NOCHOICE
  128. ECHO %CHOICE% not found; aborting!
  129. GOTO :EOF
  130.  
  131. :NOMACLIST1
  132. ECHO No MAC List provided; aborting!
  133. GOTO :EOF
  134.  
  135. :NOMACLIST2
  136. ECHO MAC List (%MACLIST%) not found; aborting!
  137. GOTO :EOF
  138.  
  139.  
  140. :END
  141. ECHO Done!
  142. endlocal
  143. GOTO :EOF
Advertisement
Add Comment
Please, Sign In to add comment