Home > Blockchain >  Capturing innerHTML of a web page via ADB Command line
Capturing innerHTML of a web page via ADB Command line

Time:02-11

I am wondering if it is possible to pull the innerHTML of a web page once it is loaded via ADB command line only.

I want to check my public IP address of my android device to verify the Proxy is active before running additional commands/services. I plan to validate the known Proxy using https://api.ipify.org

I can run the following command: adb shell am start -a android.intent.action.VIEW -d https://api.ipify.org Only problem is i have no way of grabbing the result and relaying it back via command line. I also want to avoid opening a web page on the device and have this query be done in the background.

Just to add that I am rooted which may help with the solution.

I have done a lot of research and came across this tool: https://www.cyberciti.biz/faq/unix-linux-get-the-contents-of-a-webpage-in-a-terminal but have no idea how to get this to work or even if this is the way to go.

I know how to do this using VB with the post method using a WinHttp request, but when it comes to android/linux I am completely lost!

Thanks in advance

Kind regards, Maddis :)

CodePudding user response:

Using am start to execute something you want to get the response of is a bad idea because am start works asynchronously and thus can not give you any direct response.

As it is your phone only I recommend to install a a Linux command-line tool like curl or wget to /data/local/tmp or /data/local depending on your Android version. A simple wget version is usually included in busybox so there should be a number of precompiled binaries available you can simply push to thed evice, copy to /data/local/tmp or /data/local, make it executable via chmod and then use to request your public IP using the mentioned API.

CodePudding user response:

If your goal is to get the phone's public IP address and you have a rooted device, one easier option will be to use the ifconfig command:

adb shell ifconfig

and a possible outcome might be:

radio0    Link encap:UNSPEC  
          inet addr:192.168.200.2  Bcast:192.168.200.255  Mask:255.255.255.0 
          inet6 addr: fe80::24e8:a4ff:fe93:e408/64 Scope: Link
          inet6 addr: fec0::24e8:a4ff:fe93:e408/64 Scope: Site
          inet6 addr: fec0::8cb5:8406:bc1d:dfca/64 Scope: Site
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:409 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:401 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:583888 TX bytes:66712 

lo        Link encap:UNSPEC  
          inet addr:127.0.0.1  Mask:255.0.0.0 
          inet6 addr: ::1/128 Scope: Host
          UP LOOPBACK RUNNING  MTU:65536  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:1 
          RX bytes:0 TX bytes:0 

wlan0     Link encap:UNSPEC    Driver mac80211_hwsim
          inet addr:192.168.232.2  Bcast:192.168.239.255  Mask:255.255.248.0 
          inet6 addr: fe80::15:b2ff:fe00:0/64 Scope: Link
          inet6 addr: fec0::5d12:f4d4:4e00:4ffb/64 Scope: Site
          inet6 addr: fec0::15:b2ff:fe00:0/64 Scope: Site
          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
          RX packets:25422 errors:0 dropped:0 overruns:0 frame:0 
          TX packets:7246 errors:0 dropped:0 overruns:0 carrier:0 
          collisions:0 txqueuelen:1000 
          RX bytes:19063381 TX bytes:832408 

The IP address is the one reported as inet addr. You can even grep it with:

adb shell 'ifconfig | grep -i "inet addr:"'
  • Related