Telnet/SSH 到 Java `ServerSocket`

发布于 2024-12-01 16:30:40 字数 412 浏览 1 评论 0原文

我创建了一个非常简单的 Java 程序,它在开放端口 x 上创建一个 java.net.ServerSocket,并使用 accept () 等待连接代码>.我想使用 telnet/ssh 通过端口 x 连接到该程序,以便我可以与该程序进行通信。我的问题是在连接到端口后,我的程序识别并接受连接,但 ssh 冻结。我认为这是因为我没有正确的回应。我只是想知道接下来我应该做什么。我该如何回应?

可以使用一个库,但我想了解接下来应该做什么。然而,我仍然非常感谢有人告诉我我是否真的应该使用图书馆。另外,我还了解一些基本的网络概念,例如 TCP/IP、OSI,以及数据的打包、发送和解包,但这就是我的网络知识的范围。

I created a really simple Java program that creates a java.net.ServerSocket on an open port, x, and waits for a connection using accept (). I want to use telnet/ssh to connect to the program via port x so that I can communicate with said program. My problem is after I connect to the port, my program recognizes and accepts the connection, but ssh freezes. I'm assuming this is because I don't have the proper response. I just wanna know what I should be doing next. How do I respond?

I could use a library, but I'd like to understand what should come next. However, I would still really appreciate someone telling me if I really should be using a library. Also, I know some basic networking concepts like TCP/IP, OSI, and that data gets wrapped, sent, then unwrapped, but that's the extent of my networking knowledge.

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

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

发布评论

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

评论(3

因为看清所以看轻 2024-12-08 16:30:40

SSH 是一个非常特殊的协议,涉及加密。您是否只想远程登录到默认使用纯文本的套接字?

SSH is a very specific protocol, involving encryption. Do you not just want to telnet to the socket, which uses plain-text by default?

残花月 2024-12-08 16:30:40

ssh 对于您想要实现的目标来说可能太复杂了。它冻结是因为它等待服务器的响应,但它可能永远不会得到。 ssh 还具有复杂的安全要求,您可能不希望为简单的服务器实现这些要求。

为什么不在客户端从一些非常基本的东西开始,如 教程。从那时起,您仍然可以根据需要添加特性和功能。

编辑:

使用 telnet 发送命令

客户端:

只需发出 telnet 主机端口,然后键入 say Hello World 并按 Enter 键。

服务器端:

您从客户端接收字节流。首先,您必须将其解析为字符串。然后,您可以通过查找第一个空白字符来简单地分割该字符串。前面的字符串是您的“命令”,空格后面的部分是您的“有效负载”。

在示例中,这将为您提供“say”作为命令,“Hello World”作为有效负载。

然后将“命令”与已知命令列表进行比较,然后根据您拥有的命令,您可以使用有效负载作为参数来执行它。

ssh is probably much too complicated for what you want to achieve. It freezes because it waits for a response from your server that it probably never gets. ssh has also complicated security requirements that you probably don't want to implement for your simple server.

Why don't you start with something very basic on the client side as in this tutorial. From there on, you can still add features and functionality as needed.

Edit:

Sending commands with telnet:

Client Side:

Just issue telnet host port, there you type say Hello World and hit Enter.

Server side:

You receive a stream of bytes from your client. First you have to parse it as a String. Then you could simply split this String by looking for the first whitespace character. The string before that is your 'command', the part after the whitespace is your 'payload'.

In the example this would give you 'say' as the command and 'Hello World' as the payload.

Then compare the 'command' with a list of known commands, and based on what command you have you can then execute it with the payload as an argument.

兔小萌 2024-12-08 16:30:40

除非你是密码学和网络方面的天才,否则我怀疑你能否实现 SSH 服务器。我不知道你的具体要求是什么,但你可以看看这个: http:// /www.sshtools.com/en/maverick-sshd/ 这是JAVA中的sshd(但我个人没有使用过,所以不能告诉你太多)

Unless you are an genius at cryptography and networks, I doubt you can implement an SSH server. I don't know what your exact requirements are but you may take a look at this: http://www.sshtools.com/en/maverick-sshd/ It's a sshd in JAVA(but I haven't used it personally, so can't tell you much)

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