將轉義的字串陣列傳送到管道進程

將轉義的字串陣列傳送到管道進程

我有一個 bash Linux 腳本:

echo -e '\x55\x55\xaa\xaa\x00\x00\x00\x00\x00\x00\x00\x50' | netcat -w 2 192.168.10.187 8000

現在我正在嘗試將其轉換為PowerShell,但我不確定這行字元的echo 語法是什麼。

當我剛剛這樣做時: echo '\x55\x55\xaa\xaa\x00\x00\x00\x00\x00\x00\x00\x50' | & .\nc -w 2 192.168.10.187 8000

我沒有得到任何結果,但我不確定字串是否被通過管道輸入,nc或者它是錯誤的字串。

答案1

若要檢查位元組,請使用 Format-Hex cmdlet。

PS > $bytes = [Byte[]] (0x55,0x55,0xaa,0xaa,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x50)
PS > $bytes | Format-Hex
           Path:
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000   55 55 AA AA 00 00 00 00 00 00 00 50              UUªª.......P

答案2

由於輸出限制,似乎無法使用 Powershell 完成,因此我編寫了一個小型 C# 應用程式:

        using (var stdout = Console.OpenStandardOutput())
        {
            var buffer = new Byte[]
            {
                0x55,
                0x55,
                0xaa,
                0xaa,
                0x00,
                0x00,
                0x00,
                0x00,
                0x00,
                0x00,
                0x00,
                0x50
            };
            stdout.Write(buffer, 0, buffer.Length);
        } 

相關內容