WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
System.out.println("=================");
wifiManager.setWifiEnabled(true);
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String IPAddress = intToIp(wifiInfo.getIpAddress());
System.out.println("IPAddress-->>" + IPAddress);
DhcpInfo dhcpinfo = wifiManager.getDhcpInfo();
String serverAddress = intToIp(dhcpinfo.serverAddress);
System.out.println("serverAddress-->>" + serverAddress);
其中IPAddress 是本机的IP地址,serverAddress 是你所连接的wifi热点对应的IP地址
private String intToIp(int paramInt)
{
return (paramInt & 0xFF) + "." + (0xFF & paramInt >