如何使用 Windows Netcat 发送回车符?

发布于 2024-08-26 20:48:28 字数 242 浏览 4 评论 0原文

我也想直接在 Powershell 提示符中输入,而不是通过管道输入文本文件。

Foo`r 对我不起作用。例如:

echo "RJ`r`n" | .\nc.exe -u  192.168.1.247 2639

但我真正想做的就是

.\nc.exe -u  192.168.1.247 2639

开始在提示中输入内容。

I want to type directly into the Powershell prompt too, not pipe in a text file.

Foo`r doesn't work for me. For example:

echo "RJ`r`n" | .\nc.exe -u  192.168.1.247 2639

but what I'd really like to do is just

.\nc.exe -u  192.168.1.247 2639

then start typing into the prompt.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2024-09-02 20:48:28

尝试:

"Foo`ndoes work for me"

如果您需要完整的 CRLF 序列,则:

"Foo`r`ndoes work for me"

请注意,转义字符仅适用于双引号字符串 - 而不是单引号字符串。

更新: PowerShell 目前不支持 < 中的重定向,因此您只能使用管道从交互式提示符中获取到 exe 的标准输入。 nc.exe 是否可能期望另一个字符(或转义字符)来终止输入?我知道控制台执行程序可以从 PowerShell 接收标准输入。如果您有 C# 编译器,则可以通过编译以下源代码 (csc echostdin.cs) 来查看这一点:

using System;
public class App
{
  public static void Main()
  {
    int ch;
    while ((ch = Console.In.Read()) != -1)
    {
      Console.Write((char)ch);
    }
  }
}

然后执行 exe:

PS> "foo`r`n" | .\echostdin.exe
foo

PS>

Try:

"Foo`ndoes work for me"

If you need a full CRLF sequence then:

"Foo`r`ndoes work for me"

Note that the escapes chars only work in double-quoted strings - not single quoted strings.

Update: Redirect in < is not supported in PowerShell at this time so you can only get stdin to the exe from the interactive prompt using the pipeline. Is it possible nc.exe is expecting another character (or escape char) to terminate the input? I know that console exes can receive stdin from PowerShell. If you have the C# compiler, you can see this by compiling the following source (csc echostdin.cs):

using System;
public class App
{
  public static void Main()
  {
    int ch;
    while ((ch = Console.In.Read()) != -1)
    {
      Console.Write((char)ch);
    }
  }
}

Then execute the exe:

PS> "foo`r`n" | .\echostdin.exe
foo

PS>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文