- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经阅读了很多关于该主题的内容,telnet 是一种协议(protocol),而不是简单的套接字连接,等待换行符,使用外部库等等......
底线是我需要启动并运行一个快速但肮脏的 java telnet 应用程序,不一定是可扩展的,也不一定是漂亮的,所以我试图避免使用库、系统函数调用等。我一直在尝试和测试,到目前为止,当我尝试登录路由器时(当然是通过 telnet),我没有……什么都没有。
这是到目前为止我一直在使用的代码片段,请有人给我指出正确的方向,因为我不知道我还应该尝试什么,因为我确信它必须是真正的东西我想念的简单而愚蠢。提前致谢!
Socket socket = new Socket("192.168.1.1", 23);
socket.setKeepAlive(true);
BufferedReader r = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter w = new PrintWriter(socket.getOutputStream(),true);
int c=0;
while ((c = r.read()) != -1)
System.out.print((char)c);
w.print("1234\r\n"); // also tried simply \n or \r
//w.flush();
//Thread.sleep(1000);
while ((c = r.read()) != -1)
System.out.print((char)c);
w.print("1234\r\n");
//Thread.sleep(1000);
while ((c = r.read()) != -1)
System.out.print((char)c);
socket.close();
最佳答案
如果不针对您的特定路由器进行测试,很难知道您的示例有什么问题。使用库可能是个好主意,例如 http://sadun-util.sourceforge.net/telnet_library.html看起来很容易使用。
该网站还说了以下内容:
In order to carry on the conversation, a command is issued by simply sending it on the socket's outputstream (and using the telnet newline sequence \r\n):
String command="print hello";
PrintWriter pw = new PrintWriter(
new OutputStreamWriter(s.getOutputStream()), true);
pw.print(command+"\r\n");
If the session appears to hang after login, avoid to wrap the StreamWriter into a PrintWriter and instead run an explicit flush() at the end:
Writer w = new OutputStreamWriter(s.getOutputStream());
w.print(command+"\r\n");
w.flush();
这实际上可能是您的代码的问题。
关于使用套接字的java简单telnet客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6399557/
我一直在尝试创建一个 expect 脚本来通过 telnet 自动登录到我的设备 如果expect 命令没有多种可能性,则脚本可以正常工作,登录设备。 #!/usr/bin/expect set ti
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
据我了解,Telnet 与 HTTP 一样都是一种协议(protocol)。我有这样的想法,在建立初始 TCP 连接后,Telnet 客户端会将一些 telnet 特定代码发送到另一端的服务器(在本例
我正在尝试使用 C++ 和 QT 作为 GUI 来实现 Telnet 客户端。我不知道如何处理 telnet 协商。每个 telnet 命令都以 IAC 开头,例如 IAC WILL SUPPRESS
我需要在 telnet 中进行大量测试。我正在研究一些方法来自动检测我们电子邮件服务器上的字典攻击,然后限制它们,或将它们列入黑名单等。 我现在准备运行一些测试,看看我的工作是否有返回。我想我只需下载
看来您应该能够使用 telnet 手动进行 json-rpc 调用。但是,当我尝试这样做时,服务器根本没有任何响应,我不得不关闭 telnet 客户端。我是否需要发送 header 和/或以某种方式表
看来您应该能够使用 telnet 手动进行 json-rpc 调用。但是,当我尝试这样做时,服务器根本没有任何响应,我不得不关闭 telnet 客户端。我是否需要发送 header 和/或以某种方式表
我正在使用来自 busy-box 的 Telnet 客户端。我需要与 telnet 服务器创建一个 session ,但需要根据特定条件从 C 代码创建 session ,一旦创建 session ,
我需要发出 telnet close 命令,通常,^] (Ctrl-]) 应该可以工作。(找不到任何 emacs 特定的 telnet 文档) 我怎样才能得到 telnet>当我在 emacs 中使用
几天前我买了一个新的 MTS Wi-Fi Dongle,今天在使用它时,我使用我的 Android 设备在 192.168.1.1 上进行了端口扫描,令人惊讶的是端口 23(telnet)是开放的。输
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我有一个项目要做,它是这样的: 当您打开一个 telnet 控制台并 telnet 到我的服务器时,PHP 应该响应:“你好,你叫什么名字?” 然后你输入你的名字等等。我怎样才能在 PHP 中做到这一
是否可以通过 telnet 连接到服务器并从那里 telnet 到 python 中的另一台服务器?由于有一个 Controller ,我使用用户名和密码远程登录,并且从 Controller 命令行
我选择了一个用 C 编写 Telnet 服务器和 Telnet 客户端代码的项目。我正在学习 C 编程。 有没有人尝试过这个。请告诉我如何进行以及要引用的 Material 。抱歉询问源代码。我不知道
我需要编写一个在 Windows 上运行的 Perl 脚本,以通过远程登录到 Linux 机器来不断监视 Linux 机器下的日志文件以寻找模式。但问题是,Linux 机器非常频繁地重新启动(通过一些
我是 python 新手,我正在编写一个脚本来在某些情况下“telenet”设备 IP,如果 telnet 失败则编写 SSH username@deviceIp.. 对于所有 Telnet IP,它
我正在使用 org.apache.commons.net.telnet 库与我的 Telnet 服务器建立连接,该服务器的实现与标准 RFC 854 略有不同,但没什么太可怕的。 实际上,我建立到此远
我正在使用 org.apache.commons.net.telnet 库与我的 Telnet 服务器建立连接,该服务器的实现与标准 RFC 854 略有不同,但没什么太可怕的。 实际上,我建立到此远
我的要求是从 Node js连接到Telnet客户端。 我正在使用 telnet-client包裹 我正在使用此代码进行连接 var Telnet = require('telnet-client')
我需要一个 expect 脚本来等待发出的命令完成,然后从 telnet 注销。这是脚本: spawn telnet host send "username\r" send "password\r"
我是一名优秀的程序员,十分优秀!