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 ...
随机推荐
- WSGI、flup、fastcgi、web.py的关系
Apache/lighttpd: 相当于一个request proxy,根据配置,把不同的请求转发给不同的server处理,例如静态的文件请求自己处理,这个时候它就像一个web server,对于fa ...
- 为什么for不能有序遍历数组的所有元素?(Array的设计原理)
这个题目略微浅显,但却不易讲明白.如果我告诉你,我们不能以任何代码保证可以有序遍历出一个数组的所有元素,你肯定会反驳我,因为使用for明明就可以啊!但其实不是. 一.为什么FOR不能保证遍历所有? 代 ...
- javascript之css常用属性
1. position : 属性值有absolute .fixed.relative absolute:生成绝对定位的元素,相对第一父元素进行定位: fixed : 生成绝对定位的元素,相对于浏览 ...
- js代码 设为首页 加入收藏
// JavaScript Document // 加入收藏 <a onclick="AddFavorite(window.location,document.title)" ...
- About Webkit
http://blog.csdn.net/spacetiller/article/details/5784461 一 . WebKit 简介 Webkit 是一个开放源代码的浏览器引擎 (web br ...
- WebService地址变成计算机名的解决办法
WCF 4.0 has solved this issue in some instances with a new config option that use Request Headers: & ...
- mac mysql error You must reset your password using ALTER USER statement before executing this statement.
安装完mysql 之后,登陆以后,不管运行任何命令,总是提示这个 step 1: SET PASSWORD = PASSWORD('your new password'); step 2: ALTER ...
- 焦点轮播图——myfocus焦点图库
网站网址: http://demo.jb51.net/js/myfocus/demo.html 简单3步,你即可以用上myFocus. Step 1. 在html的标签内引入相关文件 <scri ...
- RPC之Thrift学习实战
关于Thrift的学习实战请参考:http://blog.csdn.net/column/details/slimina-thrift.html
- CSS 수직 가운데 정렬 (테이블 없이!) Vertical Centering with CSS
이 방법은 테이블처럼 만들어서 테이블의 vertical-align 속성을 사용할 수 있도록 를 몇 개 세팅한다. (테이블의 vertical-align 속성은 다른 요소들에서는 굉장 ...