powershell:tcpclient
差分
このページの2つのバージョン間の差分を表示します。
| powershell:tcpclient [2025/11/20 01:45] – 作成 mikoto | powershell:tcpclient [2025/11/21 07:38] (現在) – mikoto | ||
|---|---|---|---|
| 行 42: | 行 42: | ||
| $client.Close() | $client.Close() | ||
| } | } | ||
| + | </ | ||
| + | |||
| + | ===== 受け取り方 ===== | ||
| + | |||
| + | <code powershell> | ||
| + | try { | ||
| + | # ターゲットホストへの接続 | ||
| + | $client.Connect($target, | ||
| + | $stream = $client.GetStream() | ||
| + | $stream.Write($bytesSend, | ||
| + | |||
| + | # 受信データがなくなるまで受信 | ||
| + | $receiveBuffer = New-Object byte[] 4096 | ||
| + | $responseBytes = New-Object System.Collections.Generic.List[byte] | ||
| + | |||
| + | while (($byteRead = $stream.Read($receiveBuffer, | ||
| + | $responseBytes.AddRange([System.ArraySegment[byte]]:: | ||
| + | |||
| + | # 残りのデータがあるか判定 | ||
| + | if (-not $stream.DataAvailable) { break } | ||
| + | } | ||
| + | |||
| + | # デコードして表示する | ||
| + | $response = [System.Text.Encoding]:: | ||
| + | Write-Host " | ||
| + | } catch { | ||
| + | Write-Host " | ||
| + | Write-Host " | ||
| + | } finally { | ||
| + | # クローズ処理 | ||
| + | if ($stream) {$stream.Close()} | ||
| + | if ($client) {$client.Close()} | ||
| + | } | ||
| </ | </ | ||
powershell/tcpclient.txt · 最終更新: 2025/11/21 07:38 by mikoto