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. Upgrading to MySQL 5.7---focusing on temporal types

    https://www.percona.com/blog/2016/04/27/upgrading-to-mysql-5-7-focusing-on-temporal-types/ http://ww ...

  2. careercup-中等难度 17.4

    17.4 编写一个方法,找出两个数字中最大的那一个.不得使用if-else或其他比较运算符. 解法: 我们可以通过一步步的分析来将需要用到的if-else和比较操作符去掉: If a > b, ...

  3. IIS 之 查看并发连接数

    如果要查看IIS连接数,最简单方便的方法是通过“网站统计”来查看,“网站统计”的当前在线人数可以认为是当前IIS连接数.然而,“网站统计”的当前在线人数统计时间较长,一般为10分钟或15分钟,再加上统 ...

  4. Android反射机制实现与原理

    本文介绍Android反射机制实现与原理,在介绍之前,要和Java进行比较,所以先看下Java中的反射相关知识: 一.反射的概念及在Java中的类反射 反射主要是指程序可以访问.检测和修改它本身状态或 ...

  5. JAVA_eclipse 保留Java文件时自动格式化代码和优化Import

    Eclipse 保存Java文件时自动格式化代码和优化Import Eclipse中format代码的快捷方式是ctrl+shift+F,如果大家想保存 java文件的时候 自动就格式化代码+消除不必 ...

  6. NekoHTML and Dom4j

    http://pro.ctlok.com/2010/07/java-read-html-dom4j-nekohtml.html package com.ctlok.pro; import java.i ...

  7. 解决myeclipse过期问题

    一般myeclise使用期限为30天,超过之后,会频繁的提醒你,购买软件,很讨厌,有个这个小工具,,以后再也不怕啦!!! 使用方法: 1:将这个类导入到myeclipse包中 2:运行main方法,提 ...

  8. RavenScheme简介

    RavenScheme简介 RavenScheme使用了一个运行『读入-求值-打印』循环的解释器.该解释器从标准输入反复的读入表达式,对得到的表达式求值,然后打印出结果. 如果用户键入: [加 1 2 ...

  9. 蓝牙 GameKit

    一.准备工作 1.搭建UI  2.拖线 // 图片 @property (weak, nonatomic) IBOutlet UIImageView *imageView; // 建立连接 - (IB ...

  10. mysql同时向一个表中插入多条数据问题!!见详细

    INSERT INTO `表名` (`字段1`,`字段2`,`字段3`,`字段4`) values ('数组1数据1','数组1数据2','数组1数据3','数组1数据4'), ('数组2数据1',' ...