使用adb命令获取手机ip地址

最近一个项目需要使用adb开启服务,然后客户端使用安卓设备的IP地址连接到服务。
目前每次开启服务之后,都需要在安卓设备查看IP后输入连接,非常的麻烦。于是我想着试用adb获取IP,试过ifconfig等命令都没有用。
最后我找到了以下命令:

adb shell ip addr show wlan0

wlan0就是无线网卡地址,返回内容再使用正则匹配:

inet\s(\d+?\.\d+?\.\d+?\.\d+?)/\d+

就可以拿到设备IP地址了。

 文章源页面:https://www.nnnuo.com/archives/303.html

猜你喜欢

转载自blog.csdn.net/a1808508751/article/details/127396541