Aix Telnet配置命令

网络 网络管理
下面我们对Aix Telnet的有关设置问题进行一下简单介绍。那么主要讲解了在设置过程中,一些重点的命令内容。希望对大家有用。

在AIX中设置Telnet连接方式。那么我们如何进行呢?这里我们就简单地为大家分析一下。那么,为了更好地理解Aix Telnet的设置过程。我们先来对AIX进行一下了解。

一。AIX简介
 
AIX全名为Advanced Interactive Executive,俗称“An IBM uniX”或“Advanced IBM uniX”。作为综合评价***的unix操作系统(D.H. Brown咨询公司,1998年 ),AIX是真正的第二代unix,具有性能卓越、易于使用、扩充性强、适合企业关键应用等众多特点。支持300种以上的IBM软件和超过13000家独立软件厂商的软件产品。是非常优秀的操作系统,在银行、电力系统、电信移动等企业应用很广泛。下面,我们介绍下对AIX系统的信息采集。

二。下面是一个利用apache commons-net 开源包, 使用Aix Telnet方式连接的工具类实现对AIX主机信息的采集。

因为提示符已经写死了,如果采用本例,请先按照自己的真实环境修改提示符和用户名和密码 等基本信息 。

  1. package test.collector.telnet;  
  2. import java.io.InputStream;  
  3. import java.io.PrintStream;  
  4. import org.apache.commons.net.telnet.TelnetClient;  
  5. /**  
  6.  * 利用apache net 开源包,使用Aix Telnet方式获取AIX主机信息  
  7.  * @author zhaoyl  
  8.  * @date 20008.7.21  
  9.  * @version 1.2  
  10.  */  
  11. public class NetTelnet {  
  12.  //Telnet对象  
  13.  private TelnetClienttelnetnew TelnetClient();  
  14.    
  15.  private InputStream in;  
  16.  private PrintStream out;  
  17.  //提示符。具体请telnet到AIX主机查看  
  18.  private char prompt = '#';  
  19. //telnet端口  
  20.  private String port;  
  21. //用户  
  22.  private String user;  
  23. //密码  
  24.  private String password;  
  25. //IP地址  
  26.  private String ip;  
  27.  public NetTelnet() {  
  28.     
  29.   try {  
  30.    //AIX主机IP  
  31.    this.ip = "10.1.2.222";  
  32.    this.password = "loeisdke";  
  33.    this.user = "whdiwpasdq232sd2323";  
  34.    this.port = "23";  
  35.    telnet.connect(ip, Integer.parseInt(port));  
  36.    in = telnet.getInputStream();  
  37.    out = new PrintStream(telnet.getOutputStream());  
  38. //登录   
  39.    readUntil("login: ");  
  40.    write(user);  
  41.    readUntil("Password: ");  
  42.    write(password);  
  43.    readUntil(prompt + " ");  
  44.   } catch (Exception e) {  
  45.    e.printStackTrace();  
  46.   }  
  47.  }  
  48.  /**  
  49.   * 读取分析结果  
  50.   * @param pattern  
  51.   * @return  
  52.   */  
  53.  public String readUntil(String pattern) {  
  54.   try {  
  55.    char lastChar = pattern.charAt(pattern.length() - 1);  
  56.    StringBuffer sb = new StringBuffer();  
  57.    char ch = (char) in.read();  
  58.    while (true) {  
  59. sb.append(ch);  
  60. if (ch == lastChar) {  
  61.  if (sb.toString().endsWith(pattern)) {  
  62.   return sb.toString();  
  63.  }  
  64. }  
  65. ch = (char) in.read();  
  66.    }  
  67.   } catch (Exception e) {  
  68.    e.printStackTrace();  
  69.   }  
  70.   return null;  
  71.  }  
  72.  /**  
  73.   * 写  
  74.   * @param value  
  75.   */  
  76.  public void write(String value) {  
  77.   try {  
  78.    out.println(value);  
  79.    out.flush();  
  80.   } catch (Exception e) {  
  81.    e.printStackTrace();  
  82.   }  
  83.  }  
  84. /**  
  85.  * 向目标发送命令字符串  
  86.  * @param command  
  87.  * @return  
  88.  */  
  89.  public String sendCommand(String command) {  
  90.   try {  
  91.    write(command);  
  92.    return readUntil(prompt + " ");  
  93.   } catch (Exception e) {  
  94.    e.printStackTrace();  
  95.   }  
  96.   return null;  
  97.  }  
  98.  /**  
  99.   * 关闭连接  
  100.   *  
  101.   */  
  102.  public void disconnect() {  
  103.   try {  
  104.    telnet.disconnect();  
  105.   } catch (Exception e) {  
  106.    e.printStackTrace();  
  107.   }  
  108.  }  
  109.  public static void main(String[] args) {  
  110.   try {  
  111.    NetTelnettelnetnew NetTelnet();  
  112.    //通过Aix Telnet的命令“查找主机名称”获取数据  
  113.    //命令是 "hostname"  
  114.    //不熟悉命令的参考<<AIX网络管理手册>> 
  115.    String result = telnet.sendCommand("hostname");  
  116.      
  117.    System.out.println(result);  
  118.    //***一定要关闭  
  119.    telnet.disconnect();  
  120.   } catch (Exception e) {  
  121.    e.printStackTrace();  
  122.   }  
  123.  }  

 

责任编辑:佟健 来源: 51CTO网络整理
相关推荐

2010-07-15 15:51:19

AIX telnet命

2010-07-15 15:46:01

2010-07-26 14:52:00

AIX telnet

2010-07-15 15:36:14

AIX telnet命

2010-07-26 14:40:25

2010-07-20 17:40:57

AIX telnet

2010-07-15 15:56:46

AIX TELNET命

2010-07-22 12:31:10

Aix Telnet

2010-07-15 14:32:00

AIX TELNET

2010-07-15 14:40:42

AIX TELNET

2010-07-26 14:43:33

AIX TELNET

2010-07-22 12:07:02

AIX TELNET

2010-07-22 12:19:07

2010-07-20 17:37:38

AIX TELNET

2010-07-22 11:23:02

AIX TELNET

2010-07-25 14:37:40

telnet命令

2009-12-17 09:02:04

路由器配置

2010-07-15 14:49:05

AIX TELNET

2010-07-19 13:23:03

Linux Telne

2010-07-22 09:25:09

telnet命令
点赞
收藏

51CTO技术栈公众号