正在查看: 新暖心缘 v8.1.1 应用的 IpUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 新暖心缘 v8.1.1 应用的 IpUtils.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.luanxingyuan.app.util;
import android.text.TextUtils;
import com.luanxingyuan.app.base.AppManager;
import com.tencent.qcloud.core.util.IOUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URL;
import java.util.Enumeration;
import o6.n;
import org.json.JSONException;
import org.json.JSONObject;
public class IpUtils {
public static String GetNetIp() {
String str = "";
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://pv.sohu.com/cityjson?ie=utf-8").openConnection();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
StringBuilder sb = new StringBuilder();
while (true) {
str = bufferedReader.readLine();
if (str == null) {
break;
}
sb.append(str + IOUtils.LINE_SEPARATOR_UNIX);
}
inputStream.close();
String substring = sb.substring(sb.indexOf("{"), sb.indexOf("}") + 1);
if (substring != null) {
try {
str = new JSONObject(substring).optString("cip");
if (!TextUtils.isEmpty(str)) {
if (!str.equals("127.0.0.1")) {
n.z(AppManager.f(), str);
}
StringBuilder sb2 = new StringBuilder();
sb2.append("GetNetIp: ");
sb2.append(str);
}
} catch (JSONException e8) {
e8.printStackTrace();
}
}
return str;
}
} catch (MalformedURLException e9) {
e9.printStackTrace();
} catch (IOException e10) {
e10.printStackTrace();
}
return str;
}
public static String GetNetIp3() {
String str = "";
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://whois.pconline.com.cn/ipJson.jsp?json=true").openConnection();
if (httpURLConnection.getResponseCode() == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "utf-8"));
StringBuilder sb = new StringBuilder();
while (true) {
str = bufferedReader.readLine();
if (str == null) {
break;
}
sb.append(str + IOUtils.LINE_SEPARATOR_UNIX);
}
inputStream.close();
String sb2 = sb.toString();
if (sb2 != null) {
try {
str = new JSONObject(sb2).optString("ip");
if (!TextUtils.isEmpty(str)) {
if (!str.equals("127.0.0.1")) {
n.z(AppManager.f(), str);
}
StringBuilder sb3 = new StringBuilder();
sb3.append("GetNetIp3: ");
sb3.append(str);
}
} catch (JSONException e8) {
e8.printStackTrace();
}
}
return str;
}
} catch (MalformedURLException e9) {
e9.printStackTrace();
} catch (IOException e10) {
e10.printStackTrace();
}
return str;
}
public static String getIpAddress() {
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
while (networkInterfaces.hasMoreElements()) {
Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
while (inetAddresses.hasMoreElements()) {
InetAddress nextElement = inetAddresses.nextElement();
if ((nextElement instanceof Inet4Address) && !nextElement.isLoopbackAddress()) {
nextElement.getHostAddress();
return nextElement.getHostAddress();
}
}
}
return "";
} catch (SocketException e8) {
e8.printStackTrace();
return "";
}
}
public static String getOutNetIP() {
String str = "";
try {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL("http://www.3322.org/dyndns/getip").openConnection();
httpURLConnection.setUseCaches(false);
httpURLConnection.setRequestMethod("GET");
httpURLConnection.setRequestProperty("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.7 Safari/537.36");
if (httpURLConnection.getResponseCode() == 200) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuilder sb = new StringBuilder();
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
sb.append(readLine + IOUtils.LINE_SEPARATOR_UNIX);
}
str = sb.toString();
if (!TextUtils.isEmpty(str)) {
StringBuilder sb2 = new StringBuilder();
sb2.append("getOutNetIP: ");
sb2.append(str);
if (!str.equals("127.0.0.1")) {
n.z(AppManager.f(), str);
}
}
} else {
LogUtil.i("网络连接异常,无法获取IP地址!");
}
} catch (Exception unused) {
LogUtil.i("网络连接异常,无法获取IP地址!");
}
return str;
}
}