亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 3039 | 回復(fù): 1
打印 上一主題 下一主題

關(guān)于telnet執(zhí)行l(wèi)s -la|more的顯示下頁問題 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2007-06-30 13:20 |只看該作者 |倒序瀏覽
使用commons-net包的org.apache.commons.net.telnet.*;
已經(jīng)正常成功登錄到相應(yīng)主機(jī),執(zhí)行l(wèi)s -la命令都可以,但是執(zhí)行
ls -la|more 出現(xiàn)分屏顯示的時候如何讀取按任意鍵顯示下一頁呢,請賜教

論壇徽章:
0
2 [報告]
發(fā)表于 2007-06-30 16:59 |只看該作者
我的代碼

  1. package cn.lxc.personal.swtich;


  2. import org.apache.commons.net.telnet.*;
  3. import org.apache.log4j.*;
  4. import java.io.*;

  5. public class TelnetSwitch
  6. {
  7.   private TelnetClient telnet = new TelnetClient();
  8.   private InputStream in;
  9.   private PrintStream out;
  10.   private char prompt = '$';
  11.   static Logger logger = Logger.getLogger(TelnetSwitch.class.getName());
  12.   SwitchLog4j switchlog4j = new SwitchLog4j();
  13.   StringBuffer sbc = null;
  14.   private static final int SWITCH=0;
  15.   private static final int HOST=1;
  16.   public TelnetSwitch( String server, String user, String password,int type ) {
  17.    try {
  18.          // Connect to the specified server
  19.          telnet.connect( server, 23 );

  20.          
  21.          // Get input and output stream references
  22.          in = telnet.getInputStream();
  23.          out = new PrintStream( telnet.getOutputStream() );
  24.          if(type==SWITCH){
  25.          // Log the user on
  26.                  readUntil( "Login: " );
  27.                  write( user );
  28.                  readUntil( "assword: " );
  29.                  write( password );
  30.          }
  31.          else if(type==HOST){
  32.                  readUntil( "login: " );
  33.                  write( user );
  34.                  readUntil( "assword: " );
  35.                  write( password );                 
  36.          }
  37.                  
  38.          // Advance to a prompt
  39.          readUntil( prompt + " " );
  40.          logger.info("logon successful!!!");
  41.    }
  42.    catch( Exception e ) {
  43.          e.printStackTrace();
  44.      logger.info("logon failed",e);
  45.    }
  46.   }

  47.   public void secondPassword( String password ) {
  48.     try {
  49.       write( "en" );
  50.       readUntil( "assword: " );
  51.       write( password );
  52.       prompt = '#';
  53.       readUntil( prompt + " " );
  54.       logger.info(password+"二次口令登錄成功");
  55.     }
  56.     catch( Exception e ) {
  57.       e.printStackTrace();
  58.       logger.info(password,e);
  59.     }
  60.   }

  61.   public String readUntil( String pattern ) {
  62.            try {
  63.                          char lastChar = pattern.charAt( pattern.length() - 1 );
  64.                          StringBuffer sb = new StringBuffer();
  65.                          boolean found = false;
  66.                          char ch = ( char )in.read();
  67.                          while( true ) {
  68.                           System.out.print( ch );
  69.                           sb.append( ch );
  70.                           if( ch == lastChar ) {
  71.                             if( sb.toString().endsWith( pattern ) ) {
  72.                                  return sb.toString();
  73.                             }
  74.                           }
  75.                           ch = ( char )in.read();
  76.                          }
  77.                         
  78.                    }
  79.                    catch( Exception e ) {
  80.                          e.printStackTrace();
  81.                    }
  82.                    return null;
  83.   }
  84.   public String readUntilall( String pattern ) {
  85.            try {
  86.                          char lastChar = pattern.charAt( pattern.length() - 1 );
  87.                          StringBuffer sb = new StringBuffer();
  88.                          boolean found = false;
  89.                          char ch = ( char )in.read();
  90.                          while( true ) {
  91.                           System.out.print( ch );
  92.                           sb.append( ch );
  93.                           if( ch == lastChar ) {
  94.                             if( sb.toString().substring(sb.length()-1,sb.length()).endsWith(pattern)) {                                    
  95.                                          return sb.toString();
  96.                                 }
  97.                           }
  98.                             if( sb.toString().contains("ress any key to continue")) {
  99.                                     sendAnyKey("\u0032");
  100.                             }
  101.                           ch = ( char )in.read();
  102.                          }
  103.                           
  104.                    }
  105.                    catch( Exception e ) {
  106.                          e.printStackTrace();
  107.                    }
  108.                    return null;
  109. }
  110.   public void write( String value ) {
  111.    try {
  112.          out.println( value );
  113.          out.flush();
  114.          System.out.println( value );
  115.    }
  116.    catch( Exception e ) {
  117.          e.printStackTrace();
  118.    }
  119.   }

  120.   public String sendCommand( String command ) {
  121.    try {
  122.          prompt = '#';
  123.          write( command );
  124.          return readUntil( prompt + " " );
  125.    }
  126.    catch( Exception e ) {
  127.          e.printStackTrace();
  128.    }
  129.    return null;
  130.   }
  131.   public String  sendAnyKey( String command ) {
  132.            try {
  133.                  prompt = '#';
  134.                  write( command );
  135.                 return readUntilall( prompt + " " );
  136.            }
  137.            catch( Exception e ) {
  138.                  e.printStackTrace() ;
  139.            }
  140.           return null;
  141.           }
  142.   public void disconnect() {
  143.    try {
  144.          telnet.disconnect();
  145.    }
  146.    catch( Exception e ) {
  147.          e.printStackTrace();
  148.    }
  149.   }
  150.   public static void main( String[] args ) {
  151.    try {
  152.            if(args.length<4)
  153.            {
  154.                            logger.info("參數(shù)不夠,請輸入四個參數(shù),運(yùn)行參數(shù)如下 ip 用戶名 密碼 二次密碼");
  155.                            System.exit(1);
  156.            }
  157.            logger.info("發(fā)送命令開始");
  158.            TelnetSwitch telnet = new TelnetSwitch( args[0], args[1], args[2],TelnetSwitch.SWITCH);

  159.        telnet.secondPassword(args[3]);
  160.        telnet.sendAnyKey("show fdb ");      
  161.        logger.info("發(fā)送命令結(jié)束");
  162.        telnet.disconnect();
  163.    }
  164.    catch( Exception e ) {
  165.          e.printStackTrace();
  166.    }
  167.   }
  168. }
復(fù)制代碼
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP