zoukankan      html  css  js  c++  java
  • Atitit.得到网络邻居列表java php c#.net python

    Atitit.得到网络邻居列表java php c#.net python 

     

    1获取workgroup  net view /domain1

    2得到网络邻居列表1

    3得到机器的ip  通过ping1

    4Code2

    5参考4

     

     

    1. 获取workgroup  net view /domain 

    2. 得到网络邻居列表

     

     

    C:\Users\Administrator>net view 服务器名称            注解

     

    ---------------------------------------------------------------------

    \\AT6T5TKUVHGT0IG

    \\DY

    \\GLEJSAZRY5YIIW0

    \\USER-20151223FC

    \\USER-20151225DJ

    命令成功完成。

     

    3. 得到机器的ip  通过ping

     

    作者:: 绰号:老哇的爪子 ( 全名::Attilax Akbar Al Rapanui 阿提拉克斯 阿克巴 阿尔 拉帕努伊 ) 汉字名:艾龙,  EMAIL:1466519819@qq.com

    转载请注明来源: http://blog.csdn.net/attilax

     

    4. Code

    public static void main(String[] args) {

    System.out.println(System.getProperty("file.encoding"));

    System.setProperty("file.encoding","gbk");

    System.out.println(System.getProperty("file.encoding"));

    List<String> li = Neighborhood.getNeighborhood( );

    System.out.println(AtiJson.toJson(li));

    // System.out.println( neighborhood );

    }

     

     

    private static List<String> getNeighborhood() {

    List<String> li = Lists.newArrayList();

    String line = "";

    boolean begin = false;

    String command = "net view";

    StringBuffer sb = new StringBuffer(); // 可变长

    try {

    Process process = Runtime.getRuntime().exec(command); // 该Process实例可用来控制进程并获得相关信息

    // 每个 Java 应用程序都有一个 Runtime 类实例,使应用程序能够与其运行的环境相连接。

    // 可以通过 getRuntime 方法获取当前运行时。exec(String)在单独的进程中执行指定的字符串命令

    BufferedReader br = new BufferedReader(new InputStreamReader(

    process.getInputStream(),"gbk"));

    while ((line = br.readLine()) != null) {

    System.out.println(line);

    line = line.trim();

     

    // 你的工作组千万不要命名为“命令成功完成。”或者是“The command completed successfully.”

    if (line.endsWith("命令成功完成。")

    || line.equalsIgnoreCase("The command completed successfully.")) {

    // begin=false;

    break;

    }

    if (line.endsWith("--------")) {

    begin = true;

    // next()

    continue;

    }

    if (begin) {

     

    {

    if (line.indexOf(" ") != -1)  //if line contain empty char

    line = line.substring(2, line.indexOf(" "));

    else

    line = line.substring(2, line.length());

     

    li.add(line);

    // line = line + " " + getNeighborIP(line);

    //sb.append("  ").append(line).append("\r\n");

     

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

     

    }

     

    }

    }

    br.close();

    process.waitFor(); // 导致当前线程等待,如有必要,一直要等到由该 Process 对象表示的进程已经终止。

    catch (IOException ioe) {

    System.out.println(ioe);

    catch (Exception e) {

    System.out.println(e);

    }

    //String string = sb.toString();

    //li.add(string);

    return li;

    }

     

     

    5. 参考

     

    java得到网络邻居的ip和用户名_zhoujielunyzb_新浪博客.htm

  • 相关阅读:
    IDEA永久激活方法
    idea在本地调试,spark创建hiveContext的时候报错
    MVC里面调用webservice
    log4net配置
    Linq 使用skip和take分页
    ASP.NET页面之间传递值的几种方式
    C#操作redis
    C#知识点:I/O
    C#知识点:ref和Out关键字浅谈
    C#知识点:反射
  • 原文地址:https://www.cnblogs.com/attilax/p/15198779.html
Copyright © 2011-2022 走看看