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 ...
随机推荐
- MySQL计划任务(事件调度器)(Event Scheduler)
http://www.cnblogs.com/c840136/articles/2388512.html https://dev.mysql.com/doc/refman/5.7/en/events- ...
- 第二章 使用JavaScript
只要一提到把JavaScript放在网页中,就不得不涉及Web的核心语言-HTML.在当初开发JavaScript的时候,Netscape要解决的一个重要问题就是如何让JavaScript既能在HTM ...
- 如何打开“USB调试”模式?
请首先确认您的系统版本, 点击「设置」-「关于手机」查看您当前的手机版本号. 如果您使用的是 Android 3.2及以下系统,请按以下步骤操作: STEP1:在应用列表选择「设置」进入系统设置菜单: ...
- SQL SERVER 2005 同步复制
what SQL SERVER2005复制是在不同数据库间保持数据结构和数据内容同步更新的一种方案. 由三部分构成: 发布服务器:包含了需要被发布的数据库,也就是需要向其它数据源分发内容的源数据库. ...
- word-wrap,word-break,text-wrap的区别
今晚看到了无双老师关于word-wrap,word-break区别的讲解 http://www.cnblogs.com/2050/archive/2012/08/10/2632256.html 受益 ...
- 全新的手势,侧滑返回、全局右滑返回都OUT啦!
前言 Android快速开发框架-ZBLibrary 最近将以前的 全局右滑返回 手势功能改成了 底部左右滑动手势. 为什么呢?为了解决滑动返回手势的问题. 目前有3种滑动返回手势 一.侧滑返回 代表 ...
- truncate和 delete的区别:
1.一个表要删除全部数据如何实现:①delete,②truncate EG:删除a表中的所有数据: CREATE TABLE `b` ( `id` int(11) NOT NULL AUTO_INCR ...
- UNIX V6内核源码剖析——unix v6 全貌
1. UNIX V6 运行硬件环境——PDP-11/40 PDP-11/40指令和数据都是以16比特为单位.对它而言,一个字的宽度为16比特. PDP-11/40以及周边设备的寄存器被映射到内存最高位 ...
- ADO.NET通用数据库访问类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- css关于宽度
很多时候,我们指定了某个元素的宽度,浏览器渲染时却只给这个元素一半的宽度,这时可以试试min-width属性,该属性表示浏览器不能偷懒,资源再紧张也得分配min-width指定的宽度.