用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - java代码库

java 使用 java.net.InterfaceAddress 获取网卡信息

2015-01-01 作者: java源代码大全举报

[java]代码库

import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

public class NetworkParameterDemo {
  public static void main(String[] args) throws Exception {
    Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces();
    while (en.hasMoreElements()) {
      NetworkInterface ni = en.nextElement();
      printParameter(ni);

    }
  }

  public static void printParameter(NetworkInterface ni) throws SocketException {
    System.out.println(\" Name = \" + ni.getName());
    System.out.println(\" Display Name = \" + ni.getDisplayName());
    System.out.println(\" Is up = \" + ni.isUp());
    System.out.println(\" Support multicast = \" + ni.supportsMulticast());
    System.out.println(\" Is loopback = \" + ni.isLoopback());
    System.out.println(\" Is virtual = \" + ni.isVirtual());
    System.out.println(\" Is point to point = \" + ni.isPointToPoint());
    System.out.println(\" Hardware address = \" + ni.getHardwareAddress());
    System.out.println(\" MTU = \" + ni.getMTU());

    System.out.println(\"\\nList of Interface Addresses:\");
    List<InterfaceAddress> list = ni.getInterfaceAddresses();
    Iterator<InterfaceAddress> it = list.iterator();

    while (it.hasNext()) {
      InterfaceAddress ia = it.next();
      System.out.println(\" Address = \" + ia.getAddress());
      System.out.println(\" Broadcast = \" + ia.getBroadcast());
      System.out.println(\" Network prefix length = \" + ia.getNetworkPrefixLength());
      System.out.println(\"\");
    }
  }
}
//该片段来自于http://yuncode.net


网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...