跟TMD第一次敲A+B一样~
2011-11-07 17:21
357 查看
import java.util.Enumeration; import java.net.*; public class Main { public static void main(String[] args) { try { Enumeration<NetworkInterface> interfaceList = NetworkInterface.getNetworkInterfaces(); if (null == interfaceList) { System.out.println("--No interfaces found--"); } else { while ( interfaceList.hasMoreElements() ) { NetworkInterface iface = interfaceList.nextElement(); System.out.println("Interface " + iface.getName() + ":"); Enumeration<InetAddress> addrList = iface.getInetAddresses(); if ( !addrList.hasMoreElements() ) { System.out.println("\t(No addresses for this interface)"); } while ( addrList.hasMoreElements() ) { InetAddress address = addrList.nextElement(); System.out.print("\tAddress " + ((address instanceof Inet4Address ? "(v4)" : (address instanceof Inet6Address ? "(v6)" : "(?)")))); System.out.println(": " + address.getHostAddress()); } } } } catch (SocketException se) { System.out.println("Error getting network interface:" + se.getMessage()); } for (String host : args) { try { System.out.println(host + ":"); InetAddress[] addressList = InetAddress.getAllByName(host); for (InetAddress address : addressList) { System.out.println("\t" + address.getHostName() + "/" + address.getHostAddress()); } } catch (UnknownHostException e) { System.out.println("\tUnable to find address for " + host); } } return ; } }
相关文章推荐
- 今天是第一次来这里,就像报道一样,点名而已。
- 真TMD爽,第一次找到复杂SQL的错误
- 分享给和我一样 第一次用git的同学
- HDU Safecracker(第一次用了搜索去遍历超时,第二次用for循环可以了,思路一样的)
- 第一次用CVS后的流程小结(其实VSS也一样)
- 第一次用javascript写了一个不用刷新就能实现--用户名验证的例子
- 在IT业从业这5年总结(第一次写总结)伤不起
- “互联网思维”这个词,就跟“小姐”一样,被大家用烂了。
- tabhost先简单记一下,以后再改(即使一样的,还是自己写的代码比较亲)
- 第一次接触Django的备忘录
- 昨天第一次面试,结果还不错。
- 我在CSDN上的第一次(如何解决JAVA应用程序中文乱码问题)
- 第一次记录
- 第一次团队作业——团队展示
- idea 使用git管理项目, window配置和第一次上传项目到码云
- 第一次离职
- 搞IT就像挖煤一样
- Android ListView 加载图片如何解决多张地址一样会导致部分图片加载不了的问题
- Unity 实现类似 QQ泡泡堂一样平滑行走的 基于Tile的移动算法
- 小谈后台服务过载、雪崩、过载保护的实际案例(这已经不是我第一次遇到真实雪崩案例了)