正在查看: WeatherSense v1.8.9 应用的 GetIpAddress.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: WeatherSense v1.8.9 应用的 GetIpAddress.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.emax.weather.utils;
import android.os.AsyncTask;
import anet.channel.request.Request;
import anet.channel.util.HttpConstant;
import com.alibaba.pdns.DNSResolver;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;
public class GetIpAddress {
public static synchronized String getIP(String domain) {
String hostAddress;
synchronized (GetIpAddress.class) {
try {
hostAddress = InetAddress.getByName(domain).getHostAddress();
System.out.println("lyq IP地址:" + hostAddress);
} catch (UnknownHostException e) {
System.out.println("lyq getIp Exception:" + e.toString());
e.printStackTrace();
return "";
}
}
return hostAddress;
}
public static boolean ping(String ipAddress) {
try {
boolean isReachable = InetAddress.getByName(ipAddress).isReachable(3000);
System.out.println("lyq ping status:" + isReachable);
return isReachable;
} catch (Exception e) {
System.out.println("lyq ping Exception:" + e.toString());
e.printStackTrace();
return false;
}
}
public static String getINetAddress(String host) {
Exception e;
String str;
ExecutionException e2;
InterruptedException e3;
System.out.println("lyq ip getINetAddress host:" + host);
try {
str = new MyAsyncTask().execute(host).get();
} catch (InterruptedException e4) {
e3 = e4;
str = null;
} catch (ExecutionException e5) {
e2 = e5;
str = null;
} catch (Exception e6) {
e = e6;
str = null;
}
try {
System.out.println("lyq ip getINetAddress:" + str);
} catch (InterruptedException e7) {
e3 = e7;
System.out.println("lyq getINetAddress e1:" + e3.toString());
e3.printStackTrace();
return str;
} catch (ExecutionException e8) {
e2 = e8;
e2.printStackTrace();
System.out.println("lyq getINetAddress e2:" + e2.toString());
return str;
} catch (Exception e9) {
e = e9;
e.printStackTrace();
System.out.println("lyq getINetAddress e3:" + e.toString());
return str;
}
return str;
}
public static class MyAsyncTask extends AsyncTask<String, Integer, String> {
public String ipAddress;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
public String doInBackground(String... strings) {
try {
return DNSResolver.getInstance().getIPV4ByHost(strings[0]);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public void onPostExecute(String s) {
super.onPostExecute((MyAsyncTask) s);
this.ipAddress = s;
}
}
public static class AsyncHttpURL extends AsyncTask<String, Integer, String> {
@Override
public void onPostExecute(String result) {
}
@Override
public String doInBackground(String... strings) {
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://dns.alidns.com/resolve?name=" + strings[0]).openConnection();
httpURLConnection.setConnectTimeout(5000);
httpURLConnection.setReadTimeout(10000);
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
httpURLConnection.setUseCaches(false);
httpURLConnection.setInstanceFollowRedirects(true);
httpURLConnection.setRequestMethod(Request.Method.POST);
httpURLConnection.setRequestProperty(HttpConstant.CONTENT_TYPE, "application/dns-message;charset=UTF-8");
httpURLConnection.setRequestProperty("Charset", "UTF-8");
httpURLConnection.setRequestProperty("Connection", "Keep-Alive");
httpURLConnection.connect();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine != null) {
sb.append(readLine);
} else {
bufferedReader.close();
httpURLConnection.disconnect();
return sb.toString();
}
}
} catch (Exception e) {
e.printStackTrace();
return e.toString();
}
}
}
public static boolean pingINetAddress(String host) {
Exception e;
Boolean bool;
ExecutionException e2;
InterruptedException e3;
System.out.println("lyq ip pingINetAddress host:" + host);
try {
bool = new MyAsyncTaskPing().execute(host).get();
} catch (InterruptedException e4) {
e3 = e4;
bool = false;
} catch (ExecutionException e5) {
e2 = e5;
bool = false;
} catch (Exception e6) {
e = e6;
bool = false;
}
try {
System.out.println("lyq ip pingINetAddress:" + bool);
} catch (InterruptedException e7) {
e3 = e7;
System.out.println("lyq pingINetAddress e1:" + e3.toString());
e3.printStackTrace();
return bool.booleanValue();
} catch (ExecutionException e8) {
e2 = e8;
e2.printStackTrace();
System.out.println("lyq pingINetAddress e2:" + e2.toString());
return bool.booleanValue();
} catch (Exception e9) {
e = e9;
e.printStackTrace();
System.out.println("lyq pingINetAddress e3:" + e.toString());
return bool.booleanValue();
}
return bool.booleanValue();
}
public static class MyAsyncTaskPing extends AsyncTask<String, Integer, Boolean> {
public boolean pingPass = false;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
public void onPostExecute(Boolean aBoolean) {
super.onPostExecute((MyAsyncTaskPing) aBoolean);
this.pingPass = aBoolean.booleanValue();
}
@Override
public Boolean doInBackground(String... strings) {
try {
this.pingPass = GetIpAddress.ping(strings[0]);
} catch (Exception e) {
e.printStackTrace();
}
return Boolean.valueOf(this.pingPass);
}
}
}