posts - 41,  comments - 40,  trackbacks - 0

          import java.io.IOException;
          import java.io.BufferedReader;
          import java.io.InputStreamReader;

          /*******************************************************************************
          ?*
          ?* 使用 net view /domain 得到工作組列表
          ?*
          ?* 使用 net view /domain:workgroup 得到指定工作組的機器列表
          ?*
          ?* Author: NeedJava
          ?*
          ?* Modified: 2006.09.11
          ?*
          ?* Version: 1.0
          ?*
          ?******************************************************************************/
          public class Neighborhood
          {
          ? private static String getNeighborhood( String command, String domain )
          ? {
          ??? String line="";

          ??? boolean begin=false;

          ??? StringBuffer sb=new StringBuffer();

          ??? try{ Process process=Runtime.getRuntime().exec( command );

          ???????? BufferedReader br=new BufferedReader( new InputStreamReader( process.getInputStream() ) );

          ???????? while( ( line=br.readLine() )!=null )
          ????????????? {
          ??????????????? line=line.trim();

          ??????????????? //你的工作組千萬不要命名為“命令成功完成?!被蛘呤恰癟he command completed successfully.”
          ??????????????? if( line.endsWith( "命令成功完成。" )||line.equalsIgnoreCase( "The command completed successfully." ) )
          ????????????????? {
          ??????????????????? begin=false;

          ??????????????????? break;
          ????????????????? }

          ??????????????? if( begin )
          ????????????????? {
          ??????????????????? if( domain.length()>0 )
          ????????????????????? {
          ??????????????????????? sb.append( "? " ).append( line ).append( "\r\n" );

          ??????????????????????? //System.out.println( "得到?? "+line );
          ????????????????????? }
          ??????????????????? else{ sb.append( line ).append( "\r\n" );

          ????????????????????????? //System.out.println( "得到 "+line );

          ????????????????????????? sb.append( getNeighborhood( "net view /domain:"+line, line ) );
          ??????????????????????? }
          ????????????????? }

          ??????????????? if( line.endsWith( "-" ) )
          ????????????????? {
          ??????????????????? begin=true;
          ????????????????? }
          ????????????? }

          ???????? br.close();

          ???????? process.waitFor();
          ?????? }
          ??? catch( IOException ioe )
          ???????? {
          ?????????? System.out.println( ioe );
          ???????? }
          ??? catch( Exception e )
          ???????? {
          ?????????? System.out.println( e );
          ???????? }

          ??? return sb.toString();
          ? }


          ? public static void main( String[] args )
          ? {
          ??? System.out.println( Neighborhood.getNeighborhood( "net view /domain", "" ) );
          ? }
          }

          posted on 2006-09-15 16:07 NeedJava 閱讀(640) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 烟台市| 逊克县| 赤壁市| 福建省| 滦南县| 盘锦市| 大城县| 寿宁县| 福安市| 琼中| 精河县| 珠海市| 辉南县| 涿鹿县| 滨海县| 廊坊市| 台江县| 阆中市| 白城市| 怀化市| 安新县| 黑水县| 翼城县| 沙洋县| 布尔津县| 石台县| 祥云县| 平谷区| 通海县| 阿合奇县| 武宁县| 荆门市| 德州市| 庆阳市| 北京市| 遵化市| 油尖旺区| 沛县| 绥芬河市| 牡丹江市| 建平县|