zoukankan      html  css  js  c++  java
  • java查看本机hostName可代表的ip列表【转】

    java查看本机hostName可代表的ip列表

    import java.net.InetAddress;
    
    public class ent {
        public static void main(String[] args) {
            String[] s = getAllLocalHostIP();
        }
    
        public static String[] getAllLocalHostIP() {
            String[] ret = null;
            try {
                String hostName = InetAddress.getLocalHost().getHostName();
                System.out.println("获取到的locasthost的Name为" + hostName + "可代表的IP列表:");
                if (hostName.length() > 0) {
                    InetAddress[] addrs = InetAddress.getAllByName(hostName);
                    if (addrs.length > 0) {
                        ret = new String[addrs.length];
                        for (int i = 0; i < addrs.length; i++) {
                            ret[i] = addrs[i].getHostAddress();
                            System.out.println("IP" + i + " : " + ret[i]);
                        }
                    }
                }
            } catch (Exception ex) {
                ret = null;
            }
            return ret;
        }
    
    }
  • 相关阅读:
    fabu dao fenleizhong
    net core 发布到服务器的方式
    暗示net core
    new post
    gg
    asb
    Nodejs 8.0 踩坑经验汇总
    禁止未发布的博文上首页等
    SortedList
    JSON.stringify 语法实例讲解
  • 原文地址:https://www.cnblogs.com/whatlonelytear/p/5134385.html
Copyright © 2011-2022 走看看