RbChat v4.56630229版本的 MD5 值为:d137f4b55d6b64b50641a810905f5957
以下内容为反编译后的 NetworkUtil.java 源代码,内容仅作参考
package net.x52im.rainbowav.sdk.util;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import android.telephony.TelephonyManager;
import android.util.Log;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class NetworkUtil {
private static String TAG = "NetworkUtil";
private static String regex = "^(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|[1-9])\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)\\.(1\\d{2}|2[0-4]\\d|25[0-5]|[1-9]\\d|\\d)$";
interface NetType {
public static final int CABLE = 5;
public static final int G2 = 2;
public static final int G3 = 3;
public static final int G4 = 4;
public static final int NONE = 0;
public static final int WIFI = 1;
}
public static int getApn(Context context) {
return 0;
}
public static boolean isMobileNetworkInfo(NetworkInfo networkInfo) {
return networkInfo.getType() == 0 || 50 == networkInfo.getType();
}
public static boolean is3Gor4G(Context context) {
try {
int networkType = ((TelephonyManager) context.getSystemService("phone")).getNetworkType();
Log.d("is3Gor4G", "type:" + networkType);
return true;
} catch (Exception unused) {
return false;
}
}
public static boolean isAirplaneModeOn(Context context) {
return Settings.System.getInt(context.getContentResolver(), "airplane_mode_on", 0) != 0;
}
public static boolean isWifiEnabled(Context context) {
NetworkInfo activeNetworkInfo = getActiveNetworkInfo(context);
return activeNetworkInfo != null && activeNetworkInfo.getTypeName().equalsIgnoreCase("wifi");
}
public static boolean isNetSupport(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager == null) {
return false;
}
try {
NetworkInfo[] allNetworkInfo = connectivityManager.getAllNetworkInfo();
if (allNetworkInfo != null) {
for (NetworkInfo networkInfo : allNetworkInfo) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static int getNetworkType(Context context) {
NetworkInfo activeNetworkInfo = getActiveNetworkInfo(context);
if (activeNetworkInfo != null) {
return activeNetworkInfo.getType();
}
return -1;
}
public static boolean isNetworkAvailable(Context context) {
NetworkInfo activeNetworkInfo = getActiveNetworkInfo(context);
return activeNetworkInfo != null && activeNetworkInfo.isAvailable();
}
public static boolean isWifiConnected(Context context) {
NetworkInfo activeNetworkInfo;
return (context == null || (activeNetworkInfo = getActiveNetworkInfo(context)) == null || activeNetworkInfo.getType() != 1) ? false : true;
}
public static NetworkInfo getActiveNetworkInfo(Context context) {
return ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
}
public static boolean isIp(String str) {
return (str == null || "".equals(str) || !str.matches(regex)) ? false : true;
}
public static String getLocalIPAddress() {
String str;
try {
Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
str = null;
while (!networkInterfaces.hasMoreElements()) {
try {
Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
while (true) {
if (inetAddresses.hasMoreElements()) {
InetAddress nextElement = inetAddresses.nextElement();
if (!nextElement.isLoopbackAddress()) {
str = nextElement.getHostAddress().toString();
}
}
}
if (!networkInterfaces.hasMoreElements()) {
}
} catch (SocketException e) {
e = e;
Log.e("Error", e.toString());
Log.d(TAG, "getLocalIPAddress|ip=" + str);
return null;
}
}
} catch (SocketException e2) {
e = e2;
str = null;
}
Log.d(TAG, "getLocalIPAddress|ip=" + str);
return null;
}
public static int getLocal32Ip(Context context) {
if (context == null) {
return -1;
}
WifiManager wifiManager = (WifiManager) context.getSystemService("wifi");
if (wifiManager.isWifiEnabled()) {
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
String str = TAG;
Log.d(str, "getLocalIp|ipAdd=" + ipAddress);
return ipAddress;
}
return -1;
}
public static String intToIp(int i) {
return (i & 255) + "." + ((i >> 8) & 255) + "." + ((i >> 16) & 255) + "." + ((i >> 24) & 255);
}
public static int ipToInt(String str) {
String[] split = str.split("\\.");
int intValue = new Integer(split[0]).intValue();
int intValue2 = new Integer(split[1]).intValue();
return (new Integer(split[3]).intValue() * 256 * 256 * 256) + (new Integer(split[2]).intValue() * 256 * 256) + (intValue2 * 256) + intValue;
}
public static void main(String[] strArr) {
System.out.print(isIp("192.168.0.202"));
}
}