Skip to content

Instantly share code, notes, and snippets.

@71
Created August 26, 2017 20:51
Show Gist options
  • Save 71/bca30dfbf6c9485b7ea0900324dd3a34 to your computer and use it in GitHub Desktop.
Save 71/bca30dfbf6c9485b7ea0900324dd3a34 to your computer and use it in GitHub Desktop.
PowerShell module used to easily get the status of an Ngrok user.
<#
.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 '&#34;', '"')
# 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