2012-05-25 158 views
4

現在,我想檢查一下android設備是否可以通過網絡連接到其他設備。我可以使用瀏覽器登錄到互聯網。但是當我使用adb shell連接到android模擬器並使用ping命令連接到主機時,它會失敗。adb shell ping主機不工作

[email protected]:~$ 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是主機的IP!)

但是,當我平127.0.0.1,它的工作原理。所以,我確定設備支持ping命令。我只是困惑,爲什麼它不能ping通主機,而我可以在瀏覽器中登錄到互聯網。更重要的是,任何人都可以顯示任何其他方法來檢查android的網絡能力?

感謝

+0

只是胡亂猜測 - 電話是在3G和PC在WiFi?不確定與NDK的關係.. – ligi

回答

2

您使用通過主機手機的數據連接,而不是USB連接到互聯網。因此,您的設備和主機之間沒有網絡連接。此外,由於您的主機沒有公共IP地址(它位於多個NAT級別之後,至少有一個級別從IP明顯可見),因此設備無法通過公共互聯網ping您的主機。

至於檢查網絡連接,你可以嘗試以下方法:

  • ping www.google.com

輸出:

/$ 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 
  • 檢查網絡連接:busybox ifconfig -a

輸出(剪斷了一點):

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" /> 
  • 可信的用戶瀏覽器和谷歌的組合。
1

亞行外殼平-C1 www.google.com

將返回下面的響應,如果設備有互聯網

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 

否則

ping: unknown host www.google.com