Get Android network interface IP address

回眸只為那壹抹淺笑 提交于 2019-12-05 10:14:22
DhcpInfo dhcpInfo = (WifiManager)this.context.getSystemService(Context.WIFI_SERVICE)).getDhcpInfo();
String ipaddress = intToIp(dhcpInfo.ipAddress)

intToIp(int integer) {
        return (integer & 0xFF) + "." + ((integer >> 8) & 0xFF) + "."
                + ((integer >> 16) & 0xFF) + "." + ((integer >> 24) & 0xFF);
    }

Above code should help you get the ipaddress...

to get the ip address of the client who is connecting to host through a socket you may use.. clientSocket = this.serverSocket.accept(); clientSocket.getInetAddress();

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!