commons.net.telnet使用示例
import org.apache.commons.net.telnet.TelnetClient;
import java.io.IOException;
public class TelnetDemo {
public static void main(String[] args) throws IOException {
TelnetClient telnet = new TelnetClient();
String remoteip = "10.1.1.159";
int remoteport = 9999;
telnet.connect(remoteip, remoteport);
System.out.println(telnet.isAvailable());
System.out.println(telnet.isConnected());
IOUtil.readWrite(telnet.getInputStream(), telnet.getOutputStream(),
System.in, System.out);
telnet.disconnect();
System.exit(0);
}
}
import org.apache.commons.net.io.Util; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream; /**
* This is a utility class providing a reader/writer capability required
* by the weatherTelnet, rexec, rshell, and rlogin example programs.
* The only point of the class is to hold the static method readWrite
* which spawns a reader thread and a writer thread. The reader thread
* reads from a local input source (presumably stdin) and writes the
* data to a remote output destination. The writer thread reads from
* a remote input source and writes to a local output destination.
* The threads terminate when the remote input source closes.
* *
*/ public final class IOUtil { public static final void readWrite(final InputStream remoteInput,
final OutputStream remoteOutput,
final InputStream localInput,
final OutputStream localOutput) {
Thread reader, writer; reader = new Thread() {
@Override
public void run() {
int ch; try {
while (!interrupted() && (ch = localInput.read()) != -1) {
remoteOutput.write(ch);
remoteOutput.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}; writer = new Thread() {
@Override
public void run() {
try {
Util.copyStream(remoteInput, localOutput);
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}; writer.setPriority(Thread.currentThread().getPriority() + 1);
writer.start();
reader.setDaemon(true);
reader.start(); try {
writer.join();
reader.interrupt();
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
commons.net.telnet使用示例的更多相关文章
- Java调用Telnet示例
import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.U ...
- 【Telnet】使用Telnet协议连接到远程Shell执行脚本
介绍 本文介绍如何通过Telnet协议连接到远程Shell,执行脚本,并获取执行结果: 相关文章: <[Jsch]使用SSH协议连接到远程Shell执行脚本>http://www.cnbl ...
- Apache Commons 工具类介绍及简单使用
转自:http://www.cnblogs.com/younggun/p/3247261.html Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下 ...
- Apache Commons 工具类简单使用
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下面是我这几年做开发过程中自己用过的工具类做简单介绍. 组件 功能介绍 BeanUtils 提供了对于 ...
- Apache Commons 工具集介绍
Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动.下面是我这几年做开发过程中自己用过的工具类做简单介绍. 组件 功能介绍 BeanUtils 提供了对于 ...
- java通过telnet远程至windows机器执行dos命令
准备工作,远程windows机器中开启telnet服务,将远程登录用户添加至telnetClients用户组 核心代码: import java.io.IOException; import java ...
- Apache Commons 工具类介绍及简单使用(转载)
原文链接 http://www.cnblogs.com/younggun/p/3247261.html Apache Commons包含了很多开源的工具,用于解决平时编程经常会遇到的问题,减少重复劳动 ...
- java操作telnet远程登录
import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import jav ...
- libevent安装及使用
一.安装libevent 官网:http://libevent.org/ 选择最新版本下载,我选择的是libevent-2.0.22-stable.tar.gz,然后安装README文件中描述的方法编 ...
随机推荐
- sql server日期字段值的比较
sql server中对日期字段值的比较 sql server中对日期字段的比较方式有多种,介绍几种常用的方式:用northwind库中的employees表作为用例表.1.between...and ...
- JSP:JAVA Bean在JSP中的运用
目录结构,如图: index.jsp <%@ page language="java" import="java.util.*" pageEncoding ...
- Unity3D手游-横版ACT游戏完整源代码下载
说明: 这不是武林.这不是江湖,没有道不完的恩怨,没有斩不断的情仇,更没有理不清的烦恼,这是剑的世界,一代剑魁闯入未知世界,将会为这个世界展开什么样的蓝图.让你来创造它的未来,剑魁道天下,一剑斗烛龙! ...
- Kendo UI开发教程(27): 移动应用开发简介
Kendo UI 支持开发Web应用,前面介绍的SPA,也支持开发移动应用,至于使用 HTML5 + JavaScript + CSS开发移动是不是一个好的选择不在本文的讨论之中.Kendo UI M ...
- Cocos2d-x 学习(1)—— 通过Cocos Studio创建第一个Demo
近期在工作上有了比較大的转变,自学情绪也慢慢高涨,本来一直在研究unity的技术.由于换了工作会開始接触cocos2d-x.但并不意味着停止研究unity,以后有时间还是会继续的. 公司的cocos2 ...
- Swift - 在界面上生成81个随机红,灰色圆点(SpriteKit游戏开发)
下面是生成一个“围住神经猫”游戏的初始场景: 1,界面下方会生成9*9共81个圆点,同时圆点内部添加文本标签显示索引 2,默认圆点为灰色,每行随机取两个点变为红色 3,奇数行和偶数行有一定的错位,错位 ...
- Locally weighted linear regression(局部加权线性回归)
(整理自AndrewNG的课件,转载请注明.整理者:华科小涛@http://www.cnblogs.com/hust-ghtao/) 前面几篇博客主要介绍了线性回归的学习算法,那么它有什么不足的地方么 ...
- Convert QWERTY to Dvorak
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Pract ...
- Delphi XE2 升级项目编译ralease版本,无法添加UAC解决方法
我今天把一个原来是Delphi2007的工程升级到了Delphi XE2,在编译ralease版本时候,发现无法添加UAC,我觉得可能是升级的原因,随后我用XE2新建了一个工程,但是在编译raleas ...
- 关于yaf的控制器命名,一个纠结的问题(续)
以下方案缺少loader相关的步骤,明天补上!!! 前面写过一篇<关于yaf的控制器命名,一个纠结的问题>.没想到yaf群里面也有跟我遇到一样问题的人,分享下解决办法. 写完那篇博文后,我 ...