简体   繁体   English

adb shell ping 主机不工作

[英]adb shell ping the host does not work

Right now, I want to check whether the android device can connect to another device via the net.现在,我想检查 android 设备是否可以通过网络连接到另一台设备。 I can use the browser to log into the internet.我可以使用浏览器登录互联网。 But when I use adb shell to connect to the android emulator and use the ping command to connect to the host, it fails.但是当我用adb shell连接android模拟器,用ping命令连接主机时,就失败了。

 kaiwii@ubuntu:~$ adb shell ping 192.168.145.136 PING 192.168.145.136 (192.168.145.136) 56(84) bytes of data. ^C 

(192.168.145.136 is the host's ip!) (192.168.145.136是主机的ip!)

But when I ping 127.0.0.1, it works.但是当我 ping 127.0.0.1 时,它起作用了。 So, I am definitely sure the device supports the ping command.所以,我绝对确定该设备支持 ping 命令。 I am just confused why it can not ping the host while I can log into the internet in the browser.我只是很困惑为什么它不能 ping 主机,而我可以在浏览器中登录互联网。 What's more, anyone can show any other method to check network ability in android?更重要的是,任何人都可以展示任何其他方法来检查 android 中的网络能力吗?

Thanks谢谢

You're connected to the internet using the phone's data connection, rather than USB via the host computer.您使用手机的数据连接而不是通过主机的 USB 连接到互联网。 Thus, there is no network connectivity between your device and your host.因此,您的设备和主机之间没有网络连接。 Further, as your host doesn't have a public IP address (it's behind multiple levels of NATs, at least one level being evident from the IP), it is impossible for the device to be able to ping your host via the public internet.此外,由于您的主机没有公共 IP 地址(它位于多个级别的 NAT 之后,IP 中至少有一个级别是显而易见的),因此设备不可能通过公共互联网 ping 您的主机。

As to checking for network connectivity, you can try the following:至于检查网络连接,您可以尝试以下操作:

  • ping www.google.com

The output:输出:

 / $ ping -c1 www.google.com
 PING www.google.com (74.125.236.51) 56(84) bytes of data.
 64 bytes from www.google.com (74.125.236.51): icmp_seq=1 ttl=55 time=40.8 ms
 64 bytes from www.google.com (74.125.236.51): icmp_seq=2 ttl=55 time=47.1 ms
 --- www.google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 40.850/43.999/47.148/3.149 ms
  • check network connections: busybox ifconfig -a检查网络连接: busybox ifconfig -a

The output (snipping it a bit):输出(稍微剪一下):

eth0      Link encap:Ethernet  HWaddr 5C:4C:A9:FC:B0:C0 
          inet addr:192.168.2.3  Bcast:192.168.2.255  Mask:255.255.255.0
          inet6 addr: fe80::5e4c:a9ff:fefc:b0c0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:359 errors:0 dropped:0 overruns:0 frame:0
          TX packets:275 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:87543 (85.4 KiB)  TX bytes:48382 (47.2 KiB)

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:620 errors:0 dropped:0 overruns:0 frame:0
          TX packets:620 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:74037 (72.3 KiB)  TX bytes:74037 (72.3 KiB)

rmnet0    Link encap:Ethernet  HWaddr 9E:43:B5:97:81:B1 
          inet addr:106.197.224.94  Bcast:106.197.224.95  Mask:255.255.255.252
          BROADCAST MULTICAST  MTU:2000  Metric:1
          RX packets:54337 errors:0 dropped:0 overruns:0 frame:0
          TX packets:59160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:32720935 (31.2 MiB)  TX bytes:8334589 (7.9 MiB)
<snipped value="rmnet1,rmnet2" />
sit0      Link encap:IPv6-in-IPv4 
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
<snipped value="tunl0,usb0" />
  • The trusty browser and Google combo.值得信赖的浏览器和 Google 组合。

adb shell ping -c1 www.google.com adb shell ping -c1 www.google.com

will return below response if device has internet如果设备有互联网,将返回以下响应

    PING www.google.com (xx.xx.xx.xx) 56(84) bytes of data.
64 bytes from (xx.xx.xx.xx): icmp_seq=1 ttl=61 time=25.3 ms

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 25.332/25.332/25.332/0.000 ms

or else要不然

ping: unknown host www.google.com

solution for appium: appium的解决方案:

Map<String, Object> argv = new HashMap<>();
argv.put("command", "dumpsys ");
argv.put("args", Lists.newArrayList("battery"));
String result = ((AppiumDriver) driver).executeScript("mobile: shell", argv).toString();
System.out.println(result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM