域名转化为IP

不要在UI线程运行,会报错

    public static String GetInetAddress(String  host){
        String IPAddress = "";
        InetAddress ReturnStr1 = null;
        try {
            ReturnStr1 = java.net.InetAddress.getByName(host);
            IPAddress = ReturnStr1.getHostAddress();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            return  IPAddress;
        }
        return IPAddress;
    }

你可能感兴趣的:(android)