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 得到指定工作組的機(jī)器列表
          ?*
          ?* 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();

          ??????????????? //你的工作組千萬(wàn)不要命名為“命令成功完成。”或者是“The 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 閱讀(644) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): Java
          主站蜘蛛池模板: 克什克腾旗| 汉沽区| 娄底市| 诸城市| 泸州市| 宽甸| 荔波县| 淮安市| 万源市| 贡觉县| 家居| 九龙城区| 诏安县| 孟津县| 裕民县| 加查县| 灵川县| 墨竹工卡县| 铜鼓县| 永丰县| 额济纳旗| 玉龙| 汉中市| 闽侯县| 彭水| 安宁市| 海伦市| 额敏县| 新蔡县| 鹤壁市| 孝义市| 筠连县| 铁岭市| 洛阳市| 曲靖市| 沙雅县| 通化县| 常山县| 柳州市| 蒙山县| 岳阳县|