import java.util.Enumeration;
import java.net.*; public class Test { /**
* @param args
*/
public static void main(String[] args) {
try {
Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces();
if (interfaceList == null) {
System.out.println("--No interface found--");
} else {
while (interfaceList.hasMoreElements()) {
NetworkInterface iface = interfaceList.nextElement();
System.out.println("Interface " + iface.getName() + ":");
Enumeration<InetAddress> addrList = iface.getInetAddresses();
while (addrList.hasMoreElements()) {
InetAddress address = addrList.nextElement();
if (address instanceof Inet6Address) {
System.out.println("\t v6:" + address.getHostAddress());
} else if(address instanceof Inet4Address) {
System.out.println("\t v4:" + address.getHostAddress());
} else {
System.out.println("\t " + address.getHostAddress());
}
}
}
}
} catch (SocketException e) {
System.out.println("Error getting network interfaces:" + e.getMessage());
e.printStackTrace();
}
} }

结果

Interface lo:
v6:0:0:0:0:0:0:0:1
v4:127.0.0.1
Interface net0:
Interface net1:
Interface net2:
Interface ppp0:
Interface eth0:
Interface eth1:
Interface eth2:
Interface ppp1:
Interface net3:
Interface net4:
Interface eth3:
Interface eth4:
Interface net5:
Interface eth5:
Interface net6:
Interface net7:
Interface net8:
Interface net9:
v6:fe80:0:0:0:0:100:7f:fffe%19
Interface eth6:
v6:fe80:0:0:0:995d:ea5a:42c2:75a6%20
Interface net10:
Interface eth7:
v6:fe80:0:0:0:c61:34b5:e716:b2c0%22
Interface net11:
v6:fe80:0:0:0:11d7:823:d6e6:4d1d%23
v4:172.16.119.22
Interface eth8:
Interface net12:
Interface net13:
v6:fe80:0:0:0:818f:a275:9fd5:6fde%26
Interface net14:
v6:fe80:0:0:0:fcad:518c:fb2a:8d02%27
Interface net15:
v6:fe80:0:0:0:0:5efe:c0a8:f301%28
Interface net16:
Interface eth9:
v6:fe80:0:0:0:8c7f:6874:40c6:c23e%30
v4:192.168.243.1
Interface eth10:
v6:fe80:0:0:0:c12b:9cdb:edc3:1dae%31
v4:192.168.75.1
Interface net17:
Interface net18:
v6:fe80:0:0:0:0:5efe:ac10:7716%33
Interface eth11:
Interface net19:
v6:fe80:0:0:0:0:5efe:c0a8:4b01%35
Interface eth12:
Interface eth13:
Interface net20:
Interface net21:
Interface eth14:
v6:fe80:0:0:0:d9f:7d1b:e2e3:689b%40
Interface net22:
Interface net23:
Interface net24:
Interface eth15:
Interface eth16:
Interface net25:
Interface net26:
Interface eth17:
Interface eth18:
Interface eth19:
Interface eth20:
Interface eth21:
Interface eth22:
Interface eth23:
Interface net27:
Interface net28:
Interface net29:
Interface net30:
Interface net31:
Interface net32:
Interface net33:
Interface net34:

Java遍历所有网卡打印对应IP的更多相关文章

  1. java获取本机名称、IP、MAC地址和网卡名称

    java获取本机名称.IP.MAC地址和网卡名称 摘自:https://blog.csdn.net/Dai_Haijiao/article/details/80364370 2018年05月18日 1 ...

  2. Java jacob调用打印机打印word文档

    前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...

  3. java 遍历map 方法 集合 五种的方法

    package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...

  4. 烂泥:更换ESXI5.0管理网卡及管理IP地址

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 公司的服务器基本上都是在IDC机房里面的,为了更有效的利用服务器性能.所以有几台服务器,安装的是ESXI5.0做成虚拟化. 注意目前这些服务器都是双网卡 ...

  5. Ubuntu 为网卡配置静态IP地址

    为网卡配置静态IP地址编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces并用下面的行来替换有关eth0的行:# The primar ...

  6. java 遍历文件夹里的文件

    Java遍历文件夹的2种方法: A.不使用递归: import java.io.File; import java.util.LinkedList; public class FileSystem { ...

  7. JAVA 遍历文件夹下的所有文件

    JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...

  8. java遍历树(深度遍历和广度遍历

    java遍历树如现有以下一颗树:A     B          B1               B11          B2               B22     C          C ...

  9. nginx反向代理nginx,RealServer日志打印真实ip

    title: nginx反向代理nginx,RealServer日志打印真实ip date: 2016-05-11 19:15:37 tags: --- nginx反向代理nginx,RealServ ...

随机推荐

  1. 管道技巧-while read line

    http://blog.csdn.net/hunanchenxingyu/article/details/9998089

  2. Unescape HTML entities in Javascript Unescape HTML转成html代码

    前言: 在javascript里面动态创建标准dom对象一般使用: var obj = document.createElement('div'); 然后再给obj设置一些属性. 但是,在实际使用过程 ...

  3. ADO.Net的小知识(连接数据库)二

    上次提到数据库连接有两种形式断开式连接和打开式连接,断开式连接我已经讲解了,下面我来给大家讲解一下打开式连接 (1)引入命名空间:using System.Data.SqlClient; 该语句用于导 ...

  4. linux文件 编辑常用 inux手把手vi ---针对文件操作

    命令语法 说明 使用频率(1:常用;2一般:3:偶尔) 1.VI编辑器的启动与退出 VI编辑器的启动与退出 vi  file1 新建一个文本文件名为file1 :q 退出,如果对缓存去进行过修改,则提 ...

  5. MySQL(15):Select-distinct(返回非重复的记录)

    1. 查询所有记录 和 查询 非重复记录 语法: SELECT    [ALL | DISTINCT ] All:返回所有记录 Distinct:返回非重复记录 针对获得的记录内的字段生效.   2. ...

  6. java8 之java.time

    Java 8 之 java.time 包 标签: java java8 | 发表时间:2013-10-15 08:29 | 作者:coderbee 分享到: 出处:http://coderbee.ne ...

  7. WebService地址变成计算机名的解决办法

    WCF 4.0 has solved this issue in some instances with a new config option that use Request Headers: & ...

  8. Android 自学之相对布局 RelativeLayout

    相对布局(RelativeLayout),相对布局容器内子组件的位置总是相对兄弟组件.父容器来决定的. RelativeLayout的XML属性及相关方法说明 XML属性 相关方法 说明 androi ...

  9. posix thread内存可视性

    线程间的内存可视性 当线程调用怕thread——create时, 它所能看到的内存值也是它建立的线程能够看到的.任何在调用怕thread_create之后写入的数据,可能不会被建立的线程看到,即使写操 ...

  10. docker 错误

    docker search ubuntuGet http:///var/run/docker.sock/v1.20/images/search?term=ubuntu: dial unix /var/ ...