adb端口转发初体验及其它常用命令
背景
通过adb,转发请求到android手机上。
初体验
安装adb
brew install android-platform-tools
里面的工具有
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/sload_f2fs (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/dmtracedump (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/e2fsdroid (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/etc1tool (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/fastboot (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/hprof-conv (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/make_f2fs (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/make_f2fs_casefold (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/mke2fs (Binary)
/usr/local/Caskroom/android-platform-tools/33.0.3/platform-tools/adb (Binary)
注意,还有另外一个包 android-commandlinetools
,里面的工具如下,这里面不需要安装:
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/avdmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/lint (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/retrace (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/screenshot2 (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/sdkmanager (Binary)
/usr/local/share/android-commandlinetools/cmdline-tools/latest/bin/apkanalyzer (Binary)
adb连接手机
连接手机:
adb devices
List of devices attached
ef095fab device
进入手机:
adb shell
apollo:/ $
测试手机上的socks5代理
curl -x socks5h://localhost:7777 http://www.google.com/
转发请求
将本机的6666请求,转发到手机上的7777端口上。
adb forward tcp:6666 tcp:7777
测试本机上的代理:
curl -x socks5h://localhost:6666 http://www.google.com/
其它常用命令
查看设备
adb devices
List of devices attached
aaxxxxab device
安装包
adb install -r xxx.apk
进入终端
adb shell
下载文件
adb pull /sdcard/Android/xxx .
上传文件
# 改为可读可写
adb remount
adb push file.txt /sdcard/Android/xxx
FAQ
adb devices中看不到设备
- 打开开发者模式:关于手机 -> 版本信息 -> 版本号 -> 点多下
- 打开usb调试:其他设备 -> 开发者选项 -> USB调试 (选中)
- 如果还看不到:选择USB设置 -> RNDIS(USB以太网)
- 如果偶尔有:确认一下adb版本
Android Debug Bridge version 1.0.41
Version 33.0.3-8952118
Installed as /usr/local/bin/adb
降级安装
adb install -r -d 安装包路径