Aix Telnet配置命令
在AIX中設置Telnet連接方式。那么我們如何進行呢?這里我們就簡單地為大家分析一下。那么,為了更好地理解Aix Telnet的設置過程。我們先來對AIX進行一下了解。
一。AIX簡介
AIX全名為Advanced Interactive Executive,俗稱“An IBM uniX”或“Advanced IBM uniX”。作為綜合評價***的unix操作系統(tǒng)(D.H. Brown咨詢公司,1998年 ),AIX是真正的第二代unix,具有性能卓越、易于使用、擴充性強、適合企業(yè)關鍵應用等眾多特點。支持300種以上的IBM軟件和超過13000家獨立軟件廠商的軟件產品。是非常優(yōu)秀的操作系統(tǒng),在銀行、電力系統(tǒng)、電信移動等企業(yè)應用很廣泛。下面,我們介紹下對AIX系統(tǒng)的信息采集。
二。下面是一個利用apache commons-net 開源包, 使用Aix Telnet方式連接的工具類實現(xiàn)對AIX主機信息的采集。
因為提示符已經寫死了,如果采用本例,請先按照自己的真實環(huán)境修改提示符和用戶名和密碼 等基本信息 。
- package test.collector.telnet;
- import java.io.InputStream;
- import java.io.PrintStream;
- import org.apache.commons.net.telnet.TelnetClient;
- /**
- * 利用apache net 開源包,使用Aix Telnet方式獲取AIX主機信息
- * @author zhaoyl
- * @date 20008.7.21
- * @version 1.2
- */
- public class NetTelnet {
- //Telnet對象
- private TelnetClienttelnet= new TelnetClient();
- private InputStream in;
- private PrintStream out;
- //提示符。具體請telnet到AIX主機查看
- private char prompt = '#';
- //telnet端口
- private String port;
- //用戶
- private String user;
- //密碼
- private String password;
- //IP地址
- private String ip;
- public NetTelnet() {
- try {
- //AIX主機IP
- this.ip = "10.1.2.222";
- this.password = "loeisdke";
- this.user = "whdiwpasdq232sd2323";
- this.port = "23";
- telnet.connect(ip, Integer.parseInt(port));
- in = telnet.getInputStream();
- out = new PrintStream(telnet.getOutputStream());
- //登錄
- readUntil("login: ");
- write(user);
- readUntil("Password: ");
- write(password);
- readUntil(prompt + " ");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 讀取分析結果
- * @param pattern
- * @return
- */
- public String readUntil(String pattern) {
- try {
- char lastChar = pattern.charAt(pattern.length() - 1);
- StringBuffer sb = new StringBuffer();
- char ch = (char) in.read();
- while (true) {
- sb.append(ch);
- if (ch == lastChar) {
- if (sb.toString().endsWith(pattern)) {
- return sb.toString();
- }
- }
- ch = (char) in.read();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 寫
- * @param value
- */
- public void write(String value) {
- try {
- out.println(value);
- out.flush();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 向目標發(fā)送命令字符串
- * @param command
- * @return
- */
- public String sendCommand(String command) {
- try {
- write(command);
- return readUntil(prompt + " ");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 關閉連接
- *
- */
- public void disconnect() {
- try {
- telnet.disconnect();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) {
- try {
- NetTelnettelnet= new NetTelnet();
- //通過Aix Telnet的命令“查找主機名稱”獲取數(shù)據(jù)
- //命令是 "hostname"
- //不熟悉命令的參考<<AIX網(wǎng)絡管理手冊>>
- String result = telnet.sendCommand("hostname");
- System.out.println(result);
- //***一定要關閉
- telnet.disconnect();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }