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文件中描述的方法编 ...
随机推荐
- js遍历对象的数组
遍历数组: 1.js关键for遍历 2.jquery提供each功能 ----------------------------------- $.each(array, function(){ ...
- Swift - 使用CGBlendMode改变UIImage颜色
类似于PS,Swift中也可对图片UIImage进行图层混合(blending),而且提供了相当丰富的混合模式(blendMode).本文先介绍使用其中的kCGBlendModeDestination ...
- 在webform中调用JS的技巧
一,执行删除操作,点击按钮时弹出对话框询问是否确认删除,点击确定,删除并在删除完成后弹出删除成功:点击取消不删除 1.在aspx源 代码中加入JavaScript代码 <script langu ...
- 跨服务器查询sql (摘要)
首先推荐一个神作:http://www.cnblogs.com/daniel206/archive/2008/01/16/1041748.html 大神比较详细了.而且条理很清晰. 然后摘录一些其他的 ...
- linux-mint下搭建android,angularjs,rails,html5开发环境 - qijie29896的个人空间 - 开源中国社区
linux-mint下搭建android,angularjs,rails,html5开发环境 - qijie29896的个人空间 - 开源中国社区 http://blog.csdn.net/orzor ...
- HDU 4070 Phage War
贪心,t 大的放到前面...因为感染所有cell需要的phage的总数是一定的,所以产生phage需要的时间是一定的,只需要考虑用来感染的时间,这样考虑的话,把 t 小的放后面的话,可以发现总时间的最 ...
- 性能测试之LoardRunner 手动关联一
概述: 1.什么是关联,关联的分类? 2.实例讲解 1.关联 为什么要关联?关联是应用LoadRunner进行性能测试的一项重要技能,那为什么我们要进行关联呢?当利用VuGen录制脚本时,它会拦截Cl ...
- SQLiteLog (1) no such Column:
今天在进入sqlite数据库查询的时候出现了这个问题,SQLiteLog (1) no such Column: BGZ 搜索得知这是因为数据库中没有这一列,我的sql语句为" ...
- Inverse Quadratic Interpolation (website)
Inverse Quadratic Interpolation: https://www.youtube.com/watch?v=0H7mVPTLF7Q : https://www.youtube. ...
- Android-Cannot merge new index 66195 into a non-jumbo instruction的解决的方法
转载请注明来源:http://blog.csdn.net/goldenfish1919/article/details/33729679 用eclispe打包的时候报错: [2014-06-23 13 ...