Live data from Hacker News

BeGoneAds – A Python script that blocks ads by installing common hosts files

github.com

51–60 of 97 posts

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#51
post #22
post #9

Earlier quoted context omitted.

The goal here is to make it automatically update the hosts file once in a while

Isn’t that what cron is for?

He probably wants to learn more about systemd and needs/wants a project to do it.

Yes, obviously cron would work. If systemd can do what this dev needs, what's the harm?

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#52
Reading the code one clearly sees why Python is so well suited for these kinds of applications, one-shot script executables: Really nice string ops, regex, file io etc. One of my favorite languages. The other is C# for everything else, that Python is not that suitable for: Huge complex codebases, type safeness, more strict performance requirements etc. Specially the static typing. The dynamism and lack of type annotations of Python really bothered me when I was developing a somewhat complex desktop app in it some years ago. I guess I'm a static typing guy with optional dynamism kinda person.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#53
post #47

Earlier quoted context omitted.

Systemd has a cron system too. I’m just guessing, but it might be easier to programmatically install a systemd cron job (and making sure it runs) than doing so for the old/conventional crond?

Just using cron is back compatible

Things you get with systemd that you don't get with cron unless you implement them in the script.

* Not running if the network is down.

* Not running if the download path isn't available.

* Running if the machine was off during the scheduled time.

* Monitoring and retry logic.

* Logging to syslog.

* Resource constraints.

* Random wait.

It ends up being a lot of code factored out of the actual application.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#54

Earlier quoted context omitted.

If I considered constructing a botnet of Linux workstations, your software would be an excellent candidate.

You could say the same thing about Ansible, or Chef or Puppet or any of the other millions of systems automation tools available. There are lots of ways to misuse software, I don't think that that should preclude people from writing it.

I'm quite precise about about what these tools can and cannot do on my systems. Downloading random files form the Internet isn't on the list. When you hand over the control of the hosts file to someone else, you're basically transfer control of your DNS queries.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#55
post #38

Serious question. We all realize that the economics of the internet is largely fueled by ads, so why are we so keen to block them? It’s ad revenue that have allowed technology to flourish so strongly over the last two decades.

Ads have gotten to a point where they hamper user experience. My problem with most of the ads is the amount of js tracking junk and 3rd party A/B calls that grinds the browser to a halt.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#56

Earlier quoted context omitted.

You could say the same thing about Ansible, or Chef or Puppet or any of the other millions of systems automation tools available. There are lots of ways to misuse software, I don't think that that should preclude people from writing it.

I'm quite precise about about what these tools can and cannot do on my systems. Downloading random files form the Internet isn't on the list. When you hand over the control of the hosts file to someone else, you're basically transfer control of your DNS queries.

At least for HTTP, you're hopefully using TLS for anything important and failing if the certificate isn't valid. That certainly won't remove all the risks of losing control of your DNS, but it's one good safeguard.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#57

How is this different or better than Steven Black's project? Repo: https://github.com/StevenBlack/hosts

To be completely fair with you, I didn't know this was out there. Then again, I think my solution is more elegant, especially if all the todo's are finished.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#58
post #17
post #12

Earlier quoted context omitted.

This is actually sent to the IP address 0.0.0.0, it roughly means that all the traffic of the listed hosts is routed back to localhost

In this context, it actually means a "non-routable meta-address used to designate an invalid, unknown, or non-applicable target" [1] - 127.0.0.1 is localhost, 0.0.0.0 is its own thing. [1]: https://www.howtogeek.com/225487/what-is-the-difference-betw...

Yes, you're completely right. Mixed those 2 up.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#59
post #50
post #8

Since accepting Host files from someone on the internet can be dangerous I dug into the code: The list of hosts to exclude comes from several sites here: https://github.com/anned20/begoneads/blob/2c90fcee221edf71f8... The actual application of the hosts file is here: https://github.com/anned20/begoneads/blob/2c90fcee221edf71f8... I missed something though. Is a simple domain name per line enough to send that content…

I think you may be misreading the code. It concatenates the host files at the various URLs and then inserts their contents into /etc/hosts. I only looked at a couple of those files but the ones I did used either 0.0.0.0 or 127.0.0.1 as an address combined with a domain. To be honest, this code is over-engineered. It could be a single script with a handful of functions. At the same time, it’s missing functionality suc…

Those are things that are still on a small personal todo list. I agree that it could be much simpler, but I like the elegance of it.

Re: BeGoneAds – A Python script that blocks ads by installing common hosts files

#60
post #57

How is this different or better than Steven Black's project? Repo: https://github.com/StevenBlack/hosts

To be completely fair with you, I didn't know this was out there. Then again, I think my solution is more elegant, especially if all the todo's are finished.

Patching a critical system file with python on a regular basis... What could go wrong?
Post reply on HN