Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save curtishall/e9aa924f0e79021226ad52da88157195 to your computer and use it in GitHub Desktop.

Select an option

Save curtishall/e9aa924f0e79021226ad52da88157195 to your computer and use it in GitHub Desktop.
$hex = "ff00aa55005a4343494320202020204441432020202020202055535220202020202020535553522020202020204543484f20202020204e323032363037303420303132303530202020202030313031202020202055aa00ff"
$frame = for ($i=0; $i -lt $hex.Length; $i+=2) { [Convert]::ToByte($hex.Substring($i,2), 16) }
$sw = [Diagnostics.Stopwatch]::StartNew()
$c = New-Object Net.Sockets.TcpClient
$c.Connect("10.101.240.5", 4518)
$s = $c.GetStream()
$s.Write($frame, 0, $frame.Length)
Write-Host "Sent ECHO at $($sw.ElapsedMilliseconds) ms"
Start-Sleep -Milliseconds 500
if ($s.DataAvailable) {
$b = New-Object byte[] 8192
$n = $s.Read($b, 0, $b.Length)
Write-Host "Recv $n bytes at $($sw.ElapsedMilliseconds) ms"
[Text.Encoding]::ASCII.GetString($b, 0, [Math]::Min($n, 120))
} else { Write-Host "No reply yet" }
$c.Close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment