在成功进行3G或LTE数据呼叫后,我需要获取运营商分配的IP地址。
$adb shell netcfg >> doesnt have the assigned IP address.
我试过adb shell dumpsys
和grep ip地址,但是徒劳无功。任何帮助/指针?
试试这个命令,它会帮助你获得ipaddress
$ adb shell ifconfig tiwlan0
tiwlan0是设备上wi-fi网络接口的名称。这是获取ipaddress的通用命令,
“adb shell netcfg”
它会像这样输出
usb0 DOWN 0.0.0.0 0.0.0.0 0×00001002
sit0 DOWN 0.0.0.0 0.0.0.0 0×00000080
ip6tnl0 DOWN 0.0.0.0 0.0.0.0 0×00000080
gannet0 DOWN 0.0.0.0 0.0.0.0 0×00001082
rmnet0 UP 112.79.87.220 255.0.0.0 0x000000c1
rmnet1 DOWN 0.0.0.0 0.0.0.0 0×00000080
rmnet2 DOWN 0.0.0.0 0.0.0.0 0×00000080
你也可以试试这个:
第1步:adb shell第2步:ip -f inet addr show wlan0
尝试:
adb shell ip addr show rmnet0
它将返回类似的东西:
3: rmnet0: <UP,LOWER_UP> mtu 1500 qdisc htb state UNKNOWN qlen 1000
link/[530]
inet 172.22.1.100/29 scope global rmnet0
inet6 fc01:abab:cdcd:efe0:8099:af3f:2af2:8bc/64 scope global dynamic
valid_lft forever preferred_lft forever
inet6 fe80::8099:af3f:2af2:8bc/64 scope link
valid_lft forever preferred_lft forever
这部分是您的运营商分配的IPV4
inet 172.22.1.100
这部分是您的运营商分配的IPV6
inet6 fc01:abab:cdcd:efe0:8099:af3f:2af2:8bc
根据评论:在Android 6中删除了netcfg
尝试
adb shell netcfg
要么
adb shell <device here or leave out if one device>
shell@android:/ $netcfg
您可以通过以下方式获取设备IP地址:
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"
对Version <= Marshmallow尝试此命令,
adb devices
附件38ccdc87设备列表
adb tcpip 5555
在TCP模式端口重新启动:5555
adb shell ip addr show wlan0
24:wlan0:mtu 1500 qdisc mq state UP qlen 1000 link / ether ac:c1:ee:6b:22:f1 brd ff:ff:ff:ff:ff:ff inet 192.168.0.18/24 brd 192.168.0.255 scope global wlan0 valid_lft forever preferred_lft forever inet6 fd01 :: 1d45:6b7a:a3b:5f4d / 64 scope global temporary dynamic valid_lft 287sec preferred_lft 287sec inet6 fd01 :: aec1:eeff:fe6b:22f1 / 64 scope global dynamic valid_lft 287sec preferred_lft 287sec inet6 fe80 :: aec1:eeff:fe6b:22f1 / 64范围链接valid_lft永远preferred_lft永远
要连接到您的设备,请运行此命令
adb connect 192.168.0.18
连接到192.168.0.18:5555
确保你在这个位置android-sdk \ platform-tools中有adb
尝试:
adb shell ip addr show rmnet0 | grep 'inet ' | cut -d' ' -f6|cut -d/ -f1
它将返回运营商分配的IPV4
172.22.1.215
adb shell ip addr> ippdetails.txt这将获得分配给设备的所有ip列表。
从here下载此应用程序,它将帮助您朗读所有命令。我已经运行了netcfg并将结果显示在屏幕上。
ip route | grep rmnet_data0 | cut -d" " -f1 | cut -d"/" -f1
将rmnet_data0
更改为所需的nic,在我的情况下,rmnet_data0
代表数据nic。
要获得可用的nic列表,您可以使用ip route