-
-
Save jimbrig/205be906a84816b922cb0890f1ee6656 to your computer and use it in GitHub Desktop.
NETGEAR Router DC112A reboot powershell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################################################################### | |
| ## NETGEAR Router DC112A reboot script | |
| ## Tested with Firmware: V1.0.0.18_1.0.60 | |
| ## Mark 2020 | |
| ######################################################################### | |
| #-[Variables]------------------------------------------------------------ | |
| $user = 'admin' | |
| $pass = 'admin' | |
| $routerIP = '192.168.10.1' | |
| #-[Initialisations]------------------------------------------------------ | |
| # Prepare URL | |
| $baseUrl = 'http://' + $($routerIP) | |
| # To browse router page to get form | |
| $url1 = $($baseUrl)+'/ADV_home2.htm' | |
| # Prepare auth header | |
| $pair = "$($user):$($pass)" | |
| $encodedCreds = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($pair)) | |
| $basicAuthValue = "Basic $encodedCreds" | |
| Headers = @{ Authorization = $basicAuthValue } | |
| # Search for form url | |
| $formsearch = '<form action="(?<postLink>.*)" method="post">' | |
| # Reboot button | |
| $bodyRestartPost = 'buttonSelect=2' | |
| #-[Execution]------------------------------------------------------------ | |
| # Step 1 - First web call for auth | |
| $x=Invoke-WebRequest -Uri $baseUrl -Headers $Headers | |
| # Step 2 - Browse webpage for form | |
| $x=Invoke-WebRequest -Uri $url1 -Headers $Headers | |
| # Step 3 - Search for form link | |
| $x.Content -match $formsearch | |
| $url2 = $($baseUrl) + '/' + $($matches.postlink) | |
| # Step 4 - Push reboot button | |
| $x=Invoke-WebRequest -Uri $url2 -Headers $Headers -Method POST -Body $bodyRestartPost | |
| #Ref: | |
| # https://stackoverflow.com/a/27951845/2854578 | |
| # https://stackoverflow.com/a/37323588/2854578 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment