博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java遍历所有网卡打印对应IP
阅读量:5946 次
发布时间:2019-06-19

本文共 2996 字,大约阅读时间需要 9 分钟。

import java.util.Enumeration;import java.net.*;public class Test {    /**     * @param args     */    public static void main(String[] args) {        try {            Enumeration
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
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.1Interface 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%19Interface eth6:     v6:fe80:0:0:0:995d:ea5a:42c2:75a6%20Interface net10:Interface eth7:     v6:fe80:0:0:0:c61:34b5:e716:b2c0%22Interface net11:     v6:fe80:0:0:0:11d7:823:d6e6:4d1d%23     v4:172.16.119.22Interface eth8:Interface net12:Interface net13:     v6:fe80:0:0:0:818f:a275:9fd5:6fde%26Interface net14:     v6:fe80:0:0:0:fcad:518c:fb2a:8d02%27Interface net15:     v6:fe80:0:0:0:0:5efe:c0a8:f301%28Interface net16:Interface eth9:     v6:fe80:0:0:0:8c7f:6874:40c6:c23e%30     v4:192.168.243.1Interface eth10:     v6:fe80:0:0:0:c12b:9cdb:edc3:1dae%31     v4:192.168.75.1Interface net17:Interface net18:     v6:fe80:0:0:0:0:5efe:ac10:7716%33Interface eth11:Interface net19:     v6:fe80:0:0:0:0:5efe:c0a8:4b01%35Interface eth12:Interface eth13:Interface net20:Interface net21:Interface eth14:     v6:fe80:0:0:0:d9f:7d1b:e2e3:689b%40Interface 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:

 

转载地址:http://zkbxx.baihongyu.com/

你可能感兴趣的文章
HTML5游戏开发-Box2dWeb应用(二)-碰撞以及各种连接
查看>>
SVG to Canvas在线转换工具
查看>>
我的友情链接
查看>>
python使用递归实现目录遍历
查看>>
android/java模拟登录正方教务系统
查看>>
iOS通过http post上传图片
查看>>
OpenStack Object Storage swift操作和实践
查看>>
伸展树的学习(三):源代码分析
查看>>
ES学习笔记之--ES的集群是如何组建起来的
查看>>
我的Linux生涯之YUM
查看>>
图书清单(看不完的电子书啊)
查看>>
Btrace
查看>>
瘦AP的初始化配置
查看>>
ONOS白皮书下篇之ONOS价值主张
查看>>
VSAN API 探索第 4 部分 – VSAN 磁盘映射
查看>>
从CALSSPATH加载properties文件
查看>>
asp.net GridView激发了未处理的事件“PageIndexChanging”的分析
查看>>
MPLS
查看>>
tar.xz文件如何解压
查看>>
jquery 给textarea赋值,firefox下出现[object XMLDocument]
查看>>