Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Roll your own hosts file

Options
  • 05-04-2011 8:34pm
    #1
    Registered Users Posts: 6,026 ✭✭✭


    I'm new to this, so, be gentle with me, there is probably a much easier way to do this..

    I stumbled across a post on the mathdotrandom blog, with a tidy little script to merge and prune any excess from multiple hosts sources.

    http://mathdotrandom.blogspot.com/2010/12/block-ads-on-pc-android-with-uber-hosts.html

    As stated on the site:

    How it works:

    Collect an up-to-date set of hosts files from your favourite providers, extract the individual hosts files into one folder (e.g.: c:\temp\hosts\), and rename each file to "hosts.?", e.g.: hosts.1, hosts.2, hosts.3, etc.

    Then run the MergeHosts application, supplying the location of the folder containing all your hosts files:

    java -cp "c:\temp\MergeHosts.jar" com.ri.hosts.MergeHosts "c:\temp\hosts"


    Output looks like this:

    MergeHosts - looking for "hosts.*" files in: c:\temp\hosts

    Found hosts files:
    hosts.1
    hosts.2
    hosts.3
    hosts.4
    hosts.5

    Processing: hosts.1
    14896 domains successfully extracted, with 0 collisions

    Processing: hosts.2
    20809 domains successfully extracted, with 13478 collisions

    Processing: hosts.3
    1302 domains successfully extracted, with 571 collisions

    Processing: hosts.4
    2748 domains successfully extracted, with 2555 collisions

    Processing: hosts.5
    3 domains successfully extracted, with 3 collisions

    DONE!
    Final hosts file: c:\temp\hosts\hosts.final
    Size: 667KB


    You can now locate the new uber hosts file: hosts.final, which you can use on your Android device or on your PC!

    Very quick and easy.

    There might be negatives to having a very very large hosts files on an Android device though. I have read that the hosts file is searched sequentially, which might slow down browsing, I have no idea if this is the case or not.

    If you have a rooted phone, but have not purchased Root Explorer, instructions are given on pushing your freshly rolled hosts file to the right location using a terminal emulator.


Comments

  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    Can you not just modify the /etc/hosts file directly? This does not seem very standards complient.


  • Registered Users Posts: 6,026 ✭✭✭Amalgam


    Can you not just modify the /etc/hosts file directly?

    That's what you are doing.

    Compliant..?

    Below is the hosts file taken from /etc on a just-out-of-the-box Samsung Europa. Anything you put after the first line is entirely up to you.

    127.0.0.1 localhost

    Have you visited the link? it is pretty clear, you're just merging hosts files, removing duplicates, then dumping the hosts file back on the phone.

    I merged extra phone specific lists with the hosts file AdFree Android had created on my phone.


  • Registered Users Posts: 7,860 ✭✭✭The_B_Man


    Its a bit overkill. I havent seen an ad since installing AdFree.


  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    Amalgam wrote: »
    That's what you are doing.

    Compliant..?

    Below is the hosts file taken from /etc on a just-out-of-the-box Samsung Europa. Anything you put after the first line is entirely up to you.



    Have you visited the link? it is pretty clear, you're just merging hosts files, removing duplicates, then dumping the hosts file back on the phone.

    I merged extra phone specific lists with the hosts file AdFree Android had created on my phone.

    Sorry, I should have made myself a bit clearer. I just think this tool could have been replaced by a few lines of perl. Not that it's bad, it's a decent implementation if it works, just a unusual to see special third party tools for day to day text processing.

    * Edit - Is it possible to get source access, just of out pure curiosity? I can't find anything. *


  • Registered Users Posts: 6,026 ✭✭✭Amalgam


    The source is linked below the binary, at the site.

    http://mathdotrandom.blogspot.com/2010/12/block-ads-on-pc-android-with-uber-hosts.html

    Attached to this post also.

    MergeHosts.zip - 4.1 kb


  • Advertisement
Advertisement