adb command for getting ip address assigned by ope

2019-01-30 11:42发布

I need to fetch the IPaddress assigned by the operator after a successful 3G or LTE data call.

$adb shell netcfg >> doesnt have the assigned IP address.

I tried adb shell dumpsys and grep ip address, but in vain. Any help/pointers?

9条回答
【Aperson】
2楼-- · 2019-01-30 12:09

You can get the device ip address by this way:

adb shell ip route > addrs.txt
#Case 1:Nexus 7
#192.168.88.0/23 dev wlan0  proto kernel  scope link  src 192.168.89.48

#Case 2: Smartsian T1,Huawei C8813
#default via 192.168.88.1 dev eth0  metric 30
#8.8.8.8 via 192.168.88.1 dev eth0  metric 30
#114.114.114.114 via 192.168.88.1 dev eth0  metric 30
#192.168.88.0/23 dev eth0  proto kernel  scope link  src 192.168.89.152 metric 30
#192.168.88.1 dev eth0  scope link  metric 30

ip_addrs=$(awk {'if( NF >=9){print $9;}'} addrs.txt)

echo "the device ip address is $ip_addrs"
查看更多
手持菜刀,她持情操
3楼-- · 2019-01-30 12:13

download this app from here it will help you to rum all commands. I have run netcfg and it gives the result as attached in screen.

output screen

查看更多
看我几分像从前
4楼-- · 2019-01-30 12:19
ip route | grep rmnet_data0 | cut -d" " -f1 | cut -d"/" -f1

Change rmnet_data0 to the desired nic, in my case, rmnet_data0 represents the data nic.

To get a list of the available nic's you can use ip route

查看更多
登录 后发表回答