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文件中描述的方法编 ...
随机推荐
- Java内部类——局部内部类
局部内部类,即放在“{块中}”,局部内部类,不能被成员修饰符static修饰,且内部类的成员也不能是static. 内部类中访问局部变量“{块中}”,需要将局部变量声明为final. 可以直接访问外部 ...
- linux+Qt程序如何打包发布
源地址:http://zhidao.baidu.com/link?url=UTWEoXS21B4p1L5LJmYgGBMAr0dTdXfzmaGbWeltnwQLA3Uc9_K9RcDQFFIArbx ...
- kali之ARP欺骗获取图片流
其实很简单,就两步: 1. 后接三个参数: 网卡:eth0 网关:10.0.0.1 攻击目标:10.0.0.128 2.启动监听 会弹出一个框 里面就会显示攻击目标通过浏览器访问的页面上的 ...
- Windows Azure入门教学系列 (一): 创建第一个WebRole程序
原文 Windows Azure入门教学系列 (一): 创建第一个WebRole程序 在第一篇教学中,我们将学习如何在Visual Studio 2008 SP1中创建一个WebRole程序(C#语言 ...
- WPF Popup 置顶问题
原文 WPF Popup 置顶问题 问题: 使用wpf的popup,当在popup中弹出MessageBox或者打开对话框的时候,popup总是置顶,并遮住MessageBox或对话框. 解决: 写如 ...
- 六款常用的linux C/C++ IDE
摘要: 一.AnjutaAnjuta是一个多语言的IDE,它最大的特色是灵活,同时打开多个文件,内嵌代码级的调试器(调用gdb),应用程序向导(Application wizards)可以方便的帮助你 ...
- 几种快速傅里叶变换(FFT)的C++实现
链接:http://blog.csdn.net/zwlforever/archive/2008/03/14/2183049.aspx一篇不错的FFT 文章,收藏一下. DFT的的正变换和反变换分别为( ...
- c#后台弹出提示
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "", @"<script>alert ...
- boost计算随机数和计算crc32简单示例
boost计算随机数和计算crc32简单示例 - jwybobo2007的专栏 - 博客频道 - CSDN.NET boost计算随机数和计算crc32简单示例 2013-02-18 17:14 10 ...
- android ListView中CheckBox错位的解决
貌似已经非常晚了,可是还是想记下笔记,想让今天完满. 在ListView中加了checkBox,但是发现点击改变其选中状态的时候,发现其位置错乱.状态改变的并非你选中的,百思不得其解.后面通过上网查资 ...