2 lines
880 B
JSON
2 lines
880 B
JSON
{"command_type": "powershell", "command": "New-NetFirewallRule -DisplayName GPSDIAG-TMP -Direction Inbound -Protocol TCP -LocalPort 8765 -Action Allow | Out-Null\n$l = New-Object System.Net.HttpListener\n$l.Prefixes.Add('http://+:8765/')\n$l.Start()\n$sw = [Diagnostics.Stopwatch]::StartNew()\n$got = @()\nwhile ($sw.Elapsed.TotalSeconds -lt 150 -and $got.Count -lt 1) {\n $ar = $l.BeginGetContext($null, $null)\n if ($ar.AsyncWaitHandle.WaitOne(5000)) {\n $ctx = $l.EndGetContext($ar)\n $got += $ctx.Request.Url.Query\n $b = [Text.Encoding]::UTF8.GetBytes('ok')\n $ctx.Response.OutputStream.Write($b, 0, $b.Length)\n $ctx.Response.Close()\n }\n}\n$l.Stop()\nRemove-NetFirewallRule -DisplayName GPSDIAG-TMP | Out-Null\nif ($got.Count -eq 0) { Write-Output 'NO-CONTACT' } else { $got | ForEach-Object { [uri]::UnescapeDataString($_) } }", "timeout_seconds": 200}
|