Azure function to test network connectivity on Hybrid/relay connection

using namespace System.Net

# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)

$server = $Request.Query.Server
$port = $Request.Query.Port

try {  (new-object Net.Sockets.TcpClient).Connect($server,$port) }
catch { $closed = $true }

if ($closed) { Write-host "nogo"; $body = "nogo for " + $server + ":" + $port }
Else { Write-host "yeah" ; $body = "yeah, clear paths to "  + $server + ":" + $port }

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
})

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.