Created
August 26, 2017 20:51
-
-
Save 71/bca30dfbf6c9485b7ea0900324dd3a34 to your computer and use it in GitHub Desktop.
PowerShell module used to easily get the status of an Ngrok user.
This file contains 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
<# | |
.SYNOPSIS | |
Gets the status of an Ngrok user. | |
.EXAMPLE | |
Get-NgrokStatus -Credential (Get-Credential) | |
#> | |
function Get-NgrokStatus([Parameter(Mandatory=$true)] [PSCredential] $Credential) { | |
# Find CSRF Token | |
$Req = Invoke-WebRequest 'https://dashboard.ngrok.com/user/login' -UseBasicParsing -SessionVariable Session | |
if (-not $? -or $Req.Content -notmatch '<.+csrf.+value=\"(.+)\"') { | |
return | |
} | |
$Csrf = $Matches[1] | |
# Post log-in request, and get dashboard | |
$Req = Invoke-WebRequest 'https://dashboard.ngrok.com/user/login' -UseBasicParsing -WebSession $Session ` | |
-Body @{ 'email' = $Credential.UserName ; 'password' = $Credential.GetNetworkCredential().Password ; 'csrf_token' = $Csrf } ` | |
-Headers @{ 'Referer' = 'https://dashboard.ngrok.com/user/login' } ` | |
-ContentType 'application/x-www-form-urlencoded' ` | |
-Method POST | |
if (-not $? -or $Req.Content -notmatch '<div id="preloaded" data-value="(.+?)"></div>') { | |
return | |
} | |
$Data = ConvertFrom-Json ($Matches[1] -replace '"', '"') | |
# Beautify the output | |
return @{ | |
Data = $Data ; | |
User = $Data.account_name ; | |
Tunnels = ($Data.online_tunnels | % { @{ Protocol = $_.proto ; Url = [Uri]$_.url ; Region = $_.region ; RemoteAddress = [IPAddress]$_.remote_addr ; CreatedAt = [DateTime]$_.created_at ; ExpiresAt = [Nullable[DateTime]]$_.expires_at } }) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment