Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ___ ___ _____ ___
- #| _ \ _ \_ _/ __|
- #| _/ / | || (_ |
- #|_| |_|_\ |_| \___|
- # NETWORK MONITOR
- #-------------------
- # Description: Monitors if a login on a website with a HTML login form works properly
- # Parameters:
- # -URL: The URL to the login form
- # -Username: A valid username for the page
- # -Password: The user's password
- # -FormId: The ID of the login form
- # -UsernameID: The CSS ID of the username field
- # -PasswordID: The CSS ID of the password field
- # -CheckString: A string element that only occurs if the login worked
- # ------------------
- # (c) 2015 Stephan Linke | Paessler AG
- Param(
- [string]$url = "",
- [string]$logout = "",
- [string]$username="",
- [string]$password="",
- [int]$formId = "0",
- [string]$usernameId = "",
- [string]$passwordId = "",
- [string]$checkString = ""
- )
- $loginPage = (Invoke-WebRequest -Uri "$url" -SessionVariable PRTG)
- $LoginForm = $loginPage.Forms[$formId];
- $LoginForm.Fields[$usernameId] = $username;
- $LoginForm.Fields[$passwordId] = $password;
- $result = Invoke-WebRequest -Uri ($url) -WebSession $PRTG -Method POST -Body $LoginForm.Fields
- $response_code = $result.StatusCode
- if($result.Content.Contains($checkString))
- {
- Write-Host "$response_code:Login successful - '$($Checkstring)' found.";
- # Logout
- Invoke-WebRequest -Uri $logout -SessionVariable PRTG | Out-Null;
- Remove-Variable PRTG;
- exit 0;
- }
- else
- {
- Write-Host "$response_code:Login failed or checkstring not found. Please check if the username/password combination as well as the checkstring are correct!";
- # Logout
- Invoke-WebRequest -Uri $logout -SessionVariable PRTG | Out-Null;
- Remove-Variable PRTG;
- exit 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement