[Android Software/Hacking General [Developers Only]] DiamondJohn:
This script creates a host file based on multiple host sources, with 2 levels of fallback. ie Mirrors, and last known good download

Your warranty is now void
I take no responsibility for any adverse effects to your phone or you love life
Do not apply / use this mod if you don;t understand it, or there is any risk for damage top your device or well being

YOU are responsible for what YOU do with YOUR own device, the personal information you share, and the processes you follow in regards to any suggestions, mods, or shortcuts offered here on Xda. Please be aware of the potential security and loss of privacy issues sharing information like this can produce.

Remember, each user is solely responsible for everything YOU do with YOUR device, and for the safe keeping of YOUR private information.

Requirements (for running on android)

root​

busybox (I have only tested with stericsons busybox)​

How to use.

NB: This script can be used on the device OR on Linux​

To run from Android​

Flash the install ZIP (or for Advanced users, extract the containing zip to your desired location, and change the config in "shared_constants.inc")​

Open a terminal and type​

su;
sh /data/local/DiamondJohnHostManager/download_hosts.sh;

copy the /data/local/DiamondJohnHostManager/hosts file to /system/etc/hosts

alternatively, I personally have actually symlinked the hosts file so I do not need to flip my system partition between r/w and r/o every time I wish to update my hosts file. (yes, I understand the risks of having a system file on a write-able partition)​

FINAL_DEST=/data/local/DiamondJohnHostManager/hosts;
LINK=$(ls -l /system/etc/hosts | grep "-> $FINAL_DEST");
if [ "$LINK" == "" ]; then
$bb mount -o rw,remount /system;
if [ ! -f $FINAL_DEST ]; then
$bb echo "127.0.0.1 localhost" > $FINAL_DEST;
fi;
$bb ln -sf $FINAL_DEST /system/etc/hosts;
$bb mount -o ro,remount /system;
fi;

If you run the above successfully, every time you update the script, your live host file will be updated. On my phone it means I don't have to reboot after each update.

To run on Linux

Create the directory​

mkdir -p ~/android/DiamondJohnHostManager;​

expand the containing zip into the folder​

open a terminal​

run:

bash ~/android/DiamondJohnHostManager/download_hosts.sh;

Some of the features:

1. combines multiple hosts files. see/edit the contents of the file: /data/local/DiamondJohnHostManager/hosts-sources.txt​

2. You can edit which (see point 1)​

3. On linux, I had 110 host sources, and it generated a 98MB hosts file with over 3.4M lines/domains, in <8min​

4. It allows "fallback" host sources. ie mirrors in case the original source fails. Separate each mirror with a "|". NB: They don't actually have to be a "mirror", but can simply be an "alternative" if the previous one fails.​

5. You can have multiple mirrors/fallbacks​

6. If all the mirrors fail for a line item, it will then fallback to the last known successful downloaded host for that line​

7. handles multiple formats. Some of which:​

0.0.0.0 www.domainname1.com
127.0.0.1 www.domainname2.com
www.domainname3.com

8. You can modify the whitelist and blacklist. NB: They are explicit hosts, not regex patterns ie no "*" in the domains.. Multiple files for each are supported; so you can logically group them.​

9. if a host is "wrongfully" blocked, you can check which source is the culprit. see the "previous" directory, and note the numbers relate to the host_sources.tct file, and start as the first line being 0 (commented lines are not counted)​

10. A log is provided in previous/DiamondJohnHostDownload_log.txt the top section is comma seperated and can be pasted into excel and converted to columns, The following section provides details on each individual download / source​

11. If you make ANY changes to the host_sources.txt file, all the previous become invalidated.​

Some FYI:

I Run with the default 5 hosts sources in the install zip, and it takes 100-120 seconds to update​

To monitor the end results/output, you can also use my other app TeMeFI https://xdaforums.com/android/apps-games/app-temefi-comprehensive-documentation-t3806260​

you can find the method under: Various Ungrouped Extras>Hosts File Check​

The following script is flashed from within recovery. You could also simply manually expand the zip contents to your desired location and edit the "shared_constants.inc" file appropriately

Download: 201901251428 DiamondJohn host download script installer.zip

XDA:DevDB Information

DiamondJohn Host Builder Script, Tool/Utility for all devices (see above for details)

Contributors

DiamondJohn

Version Information

Status: Stable

Current Stable Version: 201811281200

Stable Release Date: 2018-11-28

Created 2018-11-27

Last Updated 2020-05-14​