Java遍历所有网卡打印对应IP
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的更多相关文章
- java获取本机名称、IP、MAC地址和网卡名称
java获取本机名称.IP.MAC地址和网卡名称 摘自:https://blog.csdn.net/Dai_Haijiao/article/details/80364370 2018年05月18日 1 ...
- Java jacob调用打印机打印word文档
前面说了Java如何生成复杂的Word文档,今年记录下Java如何调用打印机打印word文档. 起初用的是自带的PrintJob,但是系统提供的打印机制并不成熟完整.网上的代码也是千篇一律,在我的打印 ...
- java 遍历map 方法 集合 五种的方法
package com.jackey.topic; import java.util.ArrayList;import java.util.HashMap;import java.util.Itera ...
- 烂泥:更换ESXI5.0管理网卡及管理IP地址
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 公司的服务器基本上都是在IDC机房里面的,为了更有效的利用服务器性能.所以有几台服务器,安装的是ESXI5.0做成虚拟化. 注意目前这些服务器都是双网卡 ...
- Ubuntu 为网卡配置静态IP地址
为网卡配置静态IP地址编辑文件/etc/network/interfaces:sudo vi /etc/network/interfaces并用下面的行来替换有关eth0的行:# The primar ...
- java 遍历文件夹里的文件
Java遍历文件夹的2种方法: A.不使用递归: import java.io.File; import java.util.LinkedList; public class FileSystem { ...
- JAVA 遍历文件夹下的所有文件
JAVA 遍历文件夹下的所有文件(递归调用和非递归调用) 1.不使用递归的方法调用. public void traverseFolder1(String path) { int fileNum = ...
- java遍历树(深度遍历和广度遍历
java遍历树如现有以下一颗树:A B B1 B11 B2 B22 C C ...
- nginx反向代理nginx,RealServer日志打印真实ip
title: nginx反向代理nginx,RealServer日志打印真实ip date: 2016-05-11 19:15:37 tags: --- nginx反向代理nginx,RealServ ...
随机推荐
- JQuery Mobile navbar动态刷新创建
今天突然用到须要动态改变tab页, 布局代码例如以下: <div data-role="navbar" id='divtab'> <ul id='divtabul ...
- [Effective C++ --021]必须返回对象时,别妄想返回其reference
引言 在条目20中,我们知道了值传递和引用传递的效率问题,因此在设计程序时,我们可能就尽可能来返回引用而不是值. 可是,可能会犯下面的一些错误:传递一些引用指向其实并不存在的对象. 第一节:返回临时变 ...
- 标准I/O库之缓冲
标准I/O库提供缓冲的目的是尽可能减少使用read和write调用的次数.它也对每个I/O流自动地进行缓冲管理,从而避免了应用程序需要考虑这一点所带来的麻烦. 标准I/O提供了三种类型的缓冲: (1) ...
- mysql事务问题
mysql事务: 若mysql 开启事务后START TRANSACTION ,不显示提交commit,则默认自动回滚,而不是默认自动提交.
- JavaScript网站设计实践(四)编写about.html页面,利用JavaScript和DOM,选择性的显示和隐藏DIV元素
一.现在我们在网站设计(三)的基础上,来编写about.html页面. 这个页面要用到的知识点是利用JavaScript和DOM实现选择性地显示和隐藏某些DIV about.html页面在前面我们为了 ...
- TCP/IP协议原理与应用笔记12:单播、多播和广播地址(目的地址)
根据数据接收者的接收范围,将目的地址分为单播.多播.广播. 这里目的地址的划分主要针对的是 物理地址 和 IP地址,没有涉及到端口地址,因为主要针对标识通信节点的地址(物理地址 和 IP地址)而言,和 ...
- Android_baseComponentExample
xml布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...
- HTML实现跳转到页面指定位置
<a href="#page1">跳转到页面1</a> <a href="#page2">跳转到页面2</a> ...
- 关于快速排序的Java代码实现
快速排序(Quicksort)是对冒泡排序的一种改进.它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都比另外一部分的所有数据都要小,然后再按此方法对这两部分数据分别 ...
- Xilinx 网站资源导
Xilinx 网站资源导读 ———版权声明———–本文作者 Ricky Suwww.fpganotes.comrickysu.fpga@gmail.com 欢迎转载,转载请保持原样及署名商业使用须得到 ...