如何在android仿真器中通过代码获取pc的ip地址

如何在android仿真器中通过代码获取pc的ip地址,android,android-emulator,ip,Android,Android Emulator,Ip,我正在使用此链接的代码,但获取的ip地址与我的机器不同…如何在android emulator上获取我机器的ip地址 提前感谢导入java.net包 然后写代码 try { InetAddress thisIp =InetAddress.getLocalHost(); System.out.println("IP:"+thisIp.getHostAddress()); } catch(Exception e) { e.printStackTrace(); } 如果您想访问主机 另一个解决方案是

我正在使用此链接的代码,但获取的ip地址与我的机器不同…如何在android emulator上获取我机器的ip地址


提前感谢

导入java.net包

然后写代码

try {
InetAddress thisIp =InetAddress.getLocalHost();
System.out.println("IP:"+thisIp.getHostAddress());
}
catch(Exception e) {
e.printStackTrace();
}
如果您想访问主机

另一个解决方案是在shell上运行这个

$adb shell am start-a android.intent.action.WEB_搜索-e查询“我的ip是什么”


它将显示您的系统IP

谢谢您的帮助,先生,但它会返回andorid emulator的IP地址,因为它在单机上运行时会创建自己的本地网络,我想要android emulator上我的电脑的ip地址…请帮助谢谢Aswin的帮助…你能给我一些示例,让我在shell上运行此代码,尽管java检查此问题Aswin请探索我什么是android.intent.action.WEB\u搜索这里,我是否需要为我的电脑修改它?实际上,它将开始在查询中使用web搜索,并在google搜索中为您提供ip。它只会对你有用,看看ip。查看此链接,解析它并获取您的IPT此链接显示的ip地址与我的ipconfig的ip地址不同…..您是否愿意探索我的ip地址