preface

Charles capture is often used in Android. The steps for each packet capture are extremely complicated:

  • Mobile phone open Settings -> WLAN > Find wifi Advanced Settings > Proxy: Manual > Open Charles local IP address > Mobile phone enter IP address

Especially every time the IP address input is very painful, why so troublesome? Is there a way to automatically set the proxy: perfect solution to quickly switch between no proxy and set proxy

The agent automatically sets the PAC

See Reference 1 for detailed usage

PAC, Proxy Auto Config. Proxy automatic setting. This configuration file can be set to specify which proxy the URL goes to. This configuration file can be placed on a custom server (the disadvantage is that you need to update the configuration file if the local IP address is uncertain), and placing this configuration file on the App Server does not avoid IP switching issues.

There is also a problem that when the proxy server (Charles) is not started, the PAC configuration proxy is used, so it cannot be connected to the Internet. At this point, the agent can only be turned off manually on the phone’s wifi. The next time you start the PAC configuration proxy, you will need to manually enter the address of the proxy PAC.

In summary, it is unavoidable to enter the IP address manually, either manually setting up the proxy or PAC setting up the proxy. The following ADB shell script sets up the proxy to avoid this step

Adb shell script to set up the proxy

These two commands are used primarily

Adb shell Settings put global http_proxy 10.128.213.73:8888 ADB shell Settings delete global http_proxyCopy the code

10.128.213.73 is the IP address of Charles’ host. The first command sets up the proxy, and the second clears it

disadvantages

  • Unable to access the Internet after forgetting to clear the agent. Only re-plug the USB cable through adb shell to remove the proxy

For details, see Easy_proxy

#! /bin/bash

echo "\n---------------- Support ------------------"
echo "Set default proxy easyProxy set"
echo "Set custom proxy easyProxy set ****:8888"
echo Delete proxy easyProxy clean
echo "--------------------------------------------\n"

if [ "The $1"= ="set" ];then
    if [ -n "$2" ];then
        echo "Set up a custom proxy$2"
        adb shell settings put global http_proxy $2
    else
        # get IP
        ip=$(ifconfig | sed -En 's / 127.0.0.1 / /; s/.*inet (addr:)? (([0-9] * \.) {3}[0-9]*).*/\2/p')
        echo $ip
        count=$(echo $ip | tr ' ' '\n' | wc -l )
        if [ $count -gt 1 ];then
        echo "Multiple IP addresses, please select one manually."
        exit
        fi
        default_proxy=${ip}": 8888"
        echo "The local IP is:$default_proxy"
        echo "Set the local IP proxy$default_proxy"
        adb shell settings put global http_proxy $default_proxy
    fi
elif [ "The $1"= ="clean" ];then
    echo "Clearing agent succeeded"
    adb shell settings put global http_proxy :0
else
    echo "!!! Please enter a valid operator!!"
fi
Copy the code

Copy the file to local proxy.sh

Set the local IP as the default mobile phone agent
sh proxy.sh set
# Remove mobile proxy
sh proxy.sh clean
Copy the code

Of course, you can also add aliases

Normal apps cannot runadb

Cannot run program “adb”: error=13, Permission denied. If you forget to clear the adb shell setting of the proxy, you will have to reconnect the USB cable.

reference

  • 1. Research on PAC automatic configuration of Android proxy