public class NetUtil {
private NetUtil() {
}
/**
* 获取ip前缀
*
* @return
*/
public static String getLocalIpAddressPrefix(Context context) {
String ipAddress = getLocalIpAddress(context);
return ipAddress.substring(0, ipAddress.lastIndexOf(".") + 1);
}
/**
* 获取本机IP
*
* @return
*/
@SuppressWarnings("deprecation")
public static String getLocalIpAddress(Context context) {
WifiInfo wifiInfo = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)).getConnectionInfo();
return Formatter.formatIpAddress(wifiInfo.getIpAddress());
}
}