How can I redirect HTTP requests made from an iPad?

前端 未结 17 2367
后悔当初
后悔当初 2020-12-12 09:53

Since on an iPad we cannot edit the hosts file (without jailbreaking), how can we arbitrarily redirect web traffic to another url?

This would be important for someth

17条回答
  •  遥遥无期
    2020-12-12 10:36

    It's also possible to use Weblock - AdBlock for iOS app (available for $1.99 here: https://itunes.apple.com/us/app/weblock/id558818638?mt=8) to create web traffic redirects.

    This allows you to redirect any traffic matching certain rule to specified IP address. This will emulate adding an entry to /etc/hosts on your iOS device. If the hostname set in requests is handled by the IP you direct your traffic to, you can use this to test private API or even sniff traffic sent from other apps or websites. This unfortunately works only for http/https connections.

    All this can be done only while on Wi-Fi (one of Weblock's limitations). There main advantage is that you can easily configure everything from your iOS device and there is no need to mess with DNS/proxy server configuration.

    Here's an example:

    1. I've configured Weblock like this: http://i.stack.imgur.com/c5SUh.png
    2. Opened Safari and typed in www.google.com as URL
    3. This is the output in terminal on my Mac listening for connection on port 1234:
    
        macbook-pro-tk:~ kpr$ nc -l -v -v 1234
        GET http://www.google.com/ HTTP/1.1
        Host: www.google.com
        Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
        Proxy-Connection: keep-alive
        PREF=ID=7722bc3c844a7c26:TM=1402073839:LM=1402073839:S=5bSJJsM2p0HgUP7L
        User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D201 Safari/9537.53
        Accept-Language: en-us
        Accept-Encoding: gzip, deflate
        Connection: keep-alive
    
    

    Weblock is also good to selectively redirect some URL's with regular expressions. You could redirect queries to certain endpoint only, while all other queries go to the IP returned from the DNS. This actually allows for even more fitting configuration that /etc/hosts does.

    Example: If I create a URL redirect rule for htt*://somedomain.com/api/login* and some IP and port, I will see only traffic from this URL at this IP and port, while all other traffic to somedomain.com will go directly to the IP returned by the DNS. Notice it will work for both /api/login and /api/login?someparam=somevalue thanks to the wildcard * sign at the end of the rule.

提交回复
热议问题