1)第一步获取WifiManager
Get an instance of this class by calling Context.getSystemService(Context.WIFI_SERVICE)
.
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
通过wifiManager实例可以获取:
getConfigureNetwork(): wifi的配置网络接口的属性
getConnectionInfo(): 当前wifi 连接的信息
getDhcpInfo(): 返回DHCP信息
getScanResults():返回可接入点的列表
getWifiState():返回wifi的连接状态
2)获取当前连接Wifi的信息
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
通过wifiInfo实例可以获取:
BSSID,IP,MAC,linked Speed,the received signal strength,SSID etc
3)获取IP地址,转换IP输出格式
int ipAddress = wifiInfo.getIpAddress();
String ip = intToIp(ipAddress)
public String intToIp(int i) {return ((i >> 24 ) & 0xFF ) + "."
+ ((i >> 16 ) & 0xFF) + "." + ((i >> 8 ) & 0xFF) + "." + ( i & 0xFF) ; }