我的手机有IP。 我想知道如何找回它? 在网上搜索后,我发现我只能获得当前的外部IP。(我想要我手机的本地 - 烫发IP)
谢谢,
射线。
答案 0 :(得分:10)
谷歌快速搜索发送给我: http://www.droidnova.com/get-the-ip-address-of-your-device,304.html
阅读有关如何使用第一个代码块获取wifi IP地址的评论(在本地网络上,而不是公共IP)
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
修改强>: 模拟器似乎在wifiInfo.getIpAddress()上返回0,但它在手机上工作正常。 以下代码将整数转换为ip地址:
String ipBinary = Integer.toBinaryString(ipAddress);
//Leading zeroes are removed by toBinaryString, this will add them back.
while(ipBinary.length() < 32) {
ipBinary = "0" + ipBinary;
}
//get the four different parts
String a=ipBinary.substring(0,8);
String b=ipBinary.substring(8,16);
String c=ipBinary.substring(16,24);
String d=ipBinary.substring(24,32);
//Convert to numbers
String actualIpAddress =Integer.parseInt(d,2)+"."+Integer.parseInt(c,2)+"."+Integer.parseInt(b,2)+"."+Integer.parseInt(a,2);
答案 1 :(得分:3)
你的ip将随着你连接的每个网络而改变 - 你的手机有一个mac地址 - 你想找到的是什么?
答案 2 :(得分:1)
我称之为“local-perm”的IP是localhost
IP,始终为127.0.0.1
任何其他网络适配器的IP(在这种情况下为Wifi)会根据网络而改变