




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the License); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * /licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.io.FileOutputStream;import java.util.StringTokenizer;import .telnet.TelnetClient;import .telnet.TelnetNotificationHandler;import .telnet.SimpleOptionHandler;import .telnet.EchoOptionHandler;import .telnet.TerminalTypeOptionHandler;import .telnet.SuppressGAOptionHandler;import .telnet.InvalidTelnetOptionException;/* * This is a simple example of use of TelnetClient. An external option handler * (SimpleTelnetOptionHandler) is used. Initial configuration requested by * TelnetClient will be: WILL ECHO, WILL SUPPRESS-GA, DO SUPPRESS-GA. VT100 * terminal type will be subnegotiated. * * Also, use of the sendAYT(), getLocalOptionState(), getRemoteOptionState() is * demonstrated. When connected, type AYT to send an AYT command to the server * and see the result. Type OPT to see a report of the state of the first 25 * options. * * * author Bruno DAvanzo */public class TelnetClientExample implements Runnable, TelnetNotificationHandler static TelnetClient tc = null;/* * Main for the TelnetClientExample. */public static void main(String args) throws Exception FileOutputStream fout = null;if (args.length 1) System.err.println(Usage: TelnetClientExample1 );System.exit(1);String remoteip = args0;int remoteport;if (args.length 1) remoteport = (new Integer(args1).intValue(); else remoteport = 23;try fout = new FileOutputStream(spy.log, true); catch (IOException e) System.err.println(Exception while opening the spy file: + e.getMessage();tc = new TelnetClient();TerminalTypeOptionHandler ttopt = new TerminalTypeOptionHandler(VT100, false, false, true, false);EchoOptionHandler echoopt = new EchoOptionHandler(true, false, true,false);SuppressGAOptionHandler gaopt = new SuppressGAOptionHandler(true, true,true, true);try tc.addOptionHandler(ttopt);tc.addOptionHandler(echoopt);tc.addOptionHandler(gaopt); catch (InvalidTelnetOptionException e) System.err.println(Error registering option handlers: + e.getMessage();while (true) boolean end_loop = false;try tc.connect(remoteip, remoteport);Thread reader = new Thread(new TelnetClientExample();tc.registerNotifHandler(new TelnetClientExample();System.out.println(TelnetClientExample);System.out.println(Type AYT to send an AYT telnet command);System.out.println(Type OPT to print a report of status of options (0-24);System.out.println(Type REGISTER to register a new SimpleOptionHandler);System.out.println(Type UNREGISTER to unregister an OptionHandler);System.out.println(Type SPY to register the spy (connect to port 3333 to spy);System.out.println(Type UNSPY to stop spying the connection);reader.start();OutputStream outstr = tc.getOutputStream();byte buff = new byte1024;int ret_read = 0;do try ret_read = System.in.read(buff);if (ret_read 0) if (new String(buff, 0, ret_read).startsWith(AYT) try System.out.println(Sending AYT);System.out.println(AYT response:+ tc.sendAYT(5000); catch (IOException e) System.err.println(Exception waiting AYT response: + e.getMessage(); else if (new String(buff, 0, ret_read).startsWith(OPT) System.out.println(Status of options:);for (int ii = 0; ii 0) & (end_loop = false);try tc.disconnect(); catch (IOException e) System.err.println(Exception while connecting:+ e.getMessage(); catch (IOException e) System.err.println(Exception while connecting:+ e.getMessage();System.exit(1);/* * Callback method called when TelnetClient receives an option negotiation * command. * * * param negotiation_code * - type of negotiation command received (RECEIVED_DO, * RECEIVED_DONT, RECEIVED_WILL, RECEIVED_WONT) * * param option_code * - code of the option negotiated * */ Overridepublic void receivedNegotiation(int negotiation_code, int option_code) String command = null;if (negotiation_code = TelnetNotificationHandler.RECEIVED_DO) command = DO; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_DONT) command = DONT; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_WILL) command = WILL; else if (negotiation_code = TelnetNotificationHandler.RECEIVED_WONT) command = WONT;System.out.println(Received + command + for option code + option_code);/* * Reader thread. Reads lines from the TelnetClient and echoes them on the * screen. */ Overridepublic void run() InputStream instr = tc.getInputStream();try byte buff = new byte1024;int ret_read = 0;do ret_read = instr.read(buff);if (r
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 期中专题复习-词汇句型训练-2025-2026学年 译林版2024 英语七年级上册 原卷
- 20xx教师节感谢信3篇
- 文化遗产法律政策与文化产业发展研究-洞察及研究
- 【2025年秋七上语文阶段测试】第2单元学业质量评价01(解析版)
- 车驾管窗口业务课件培训
- 基于区块链的分布式能源交易场景下的仪表数据确权机制
- 基于人工智能的刺五加提取物多靶点作用机制预测模型构建
- 城市热岛效应缓解工程中列管散热器的分布式微气候调控效能评估
- 国际安全认证体系下扳手抗冲击测试标准与本土化适配冲突
- 四方结构力学性能优化与用户使用习惯冲突
- 新生儿低钙血症
- 熔化和凝固 全国公开课一等奖
- 人工智能训练师基础(上册)
- 中国驻外领使馆地区分类
- 粘多糖贮积症专家讲座
- 教学课件 国际结算(第七版)苏宗祥
- 成都燃气公司招聘笔试题
- 某铁路站房钢筋工程技术交底
- SMM英国建筑工程标准计量规则中文版全套
- 颈动脉保护装选择
- 水泥熟料生产工艺及设备课件
评论
0/150
提交评论