简体   繁体   English

Android 设备无法通过 adb shell ping PC

[英]Android device can't ping PC through adb shell

I have my Android phone connected to my PC (Windows 10 with Android SDK installed).我已将 Android 手机连接到我的 PC(安装了 Android SDK 的 Windows 10)。 I set up my PC to have a mobile hotspot so the phone can be connected to the PC network.我将我的 PC 设置为具有移动热点,以便手机可以连接到 PC 网络。 My PC can ping the phone's IP address, but when I want to ping the PC from the phone's shell (through adb shell ), it just can't ping it.我的电脑可以 ping 手机的 IP 地址,但是当我想从手机外壳(通过adb shell )ping 电脑时,它就是无法 ping 通它。 I have a HTTP server on the PC and need the phone to reach to the server, which is not reachable right now.我在 PC 上有一个 HTTP 服务器,需要手机连接到服务器,但现在无法访问。

The PC IP address is 192.168.137.1 : PC IP 地址是192.168.137.1

Wireless LAN adapter Local Area Connection* 2:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::345d:2505:82fa:3cd5%9
   IPv4 Address. . . . . . . . . . . : 192.168.137.1
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . :

And the phone's IP address is 192.168.137.159 :电话的 IP 地址是192.168.137.159

wlan0     Link encap:UNSPEC
          inet addr:192.168.137.159  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::5ca7:98ff:feea:cb17/64 Scope: Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:16441523 errors:0 dropped:0 overruns:0 frame:0
          TX packets:8750144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:17116348103 TX bytes:4458547550

I also tried it without mobile hotspot when both connect to the same router, but same issue again.当两者都连接到同一路由器时,我也尝试了没有移动热点的情况,但又出现了同样的问题。

What is the problem?问题是什么? Does Windows have some settings that need to be changed for visibility and reachability? Windows 是否有一些设置需要更改以提高可见性和可达性?

You are already connected via adb (as you mentioned adb shell ), then just do a reverse port mapping ( changes ports according to your case )您已经通过adb连接(正如您提到的adb shell ),然后只需进行反向端口映射(根据您的情况更改端口

adb reverse tcp:8080 tcp:8080

then, when your device access localhost:8080 it will be redirected to yourpc:8080 .然后,当您的设备访问localhost:8080 ,它将被重定向到yourpc:8080

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

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