public static String getWIFILocalIpAdress(Context mContext) {
//获取wifi服务
WifiManager wifiManager = (WifiManager)mContext.getSystemService(Context.WIFI_SERVICE);
//判断wifi是否开启
if (!wifiManager.isWifiEnabled()) {
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
String ip = formatIpAddress(ipAddress);
return ip;
}
private static String formatIpAddress(int ipAdress) {
return (ipAdress & 0xFF ) + "." +
((ipAdress >> 8 ) & 0xFF) + "." +
((ipAdress >> 16 ) & 0xFF) + "." +
( ipAdress >> 24 & 0xFF) ;
}
查看手机本地ip地址
最新推荐文章于 2021-05-26 08:39:08 发布