Getting the stats out of Pi-Hole

If you want to be informed about your Pi-Hole statistics, but don’t want to visit the Pi-Hole dashboard all the time, then there is also an alternative way to get the statistics out of Pi-Hole, and use the numbers to present it in any other way that meets your demands. This could be e.g. showing it on a display (like the Scroll pHAT HD), uploading it to ThingSpeak, or whatever else you can think of.

Pi-Hole already provides you the opportunity to make a request for getting some statistic data right out of the box.  You just have to put the following line in the address bar of your browser and replace IPOFYOURPIRUNNINGPIHOLE with the IP address of your Raspberry Pi, on which Pi-Hole is running, and you will get a list with various numbers and the description for them.


The result is given to you in the JSON data format and can easily be processed with Python, just like shown in previous scripts here in the blog before.


The following small Python script gets the data, extracts some interesting information,  formats it, and then outputs the final text on the command line.

#!/usr/bin/env python

import json
import urllib2

    f = urllib2.urlopen('http://IPOFYOURPIRUNNINGPIHOLE/admin/api.php')
    json_string =
    parsed_json = json.loads(json_string)
    queries = parsed_json['dns_queries_today']
    adsblocked = parsed_json['ads_blocked_today']
    clients = parsed_json['unique_clients']
    queries = '-'
    adsblocked = '-'
    clients = '-'

pihole = 'DNS-Queries: ' + str(queries) + ' - ' + 'Ads blocked: ' + str(adsblocked) + ' - ' + 'Devices: ' + str(clients)
print pihole


Network-wide ad blocking with the help of your Pi

Recently, I bought a new 55″ Samsung UHD Smart-TV, because my satellite receiver broke down and my TV was already relatively old. All in all, I was quite happy with the new TV, but soon I noticed that some local TV stations are abusing HbbTV for showing advertisement and that it also is not possible to uninstall certain apps that come together with the software of the TV.

First of all, I disabled the HbbTV functionality, since it is almost completely used for advertisement purposes. The media centers provided by the TV station can also be accessed by separate Smart-TV apps, so there is no need to visit it via HbbTV at all.

But there was still the problem of the pre-installed apps which were transfering data, even if the TV is in standby. Furthermore, I have noticed that Samsung uses a technology called Automatic content recognition for analyzing what you are watching.

While looking for a solution to prevent all the unwanted data transfer and the spying, I stumbled upon a project called Pi-Hole. It is a small DNS-Server which is also able to filter the incoming DNS-Requests . Instead of entering the DNS-Server directly in your router, you can just tell him to use the Raspberry Pi as the DNS-Server. The Rasperry Pi then makes the actual DNS-Requests, and in case the requested domain is advertisement, or other unwanted content, it just blocks it.


Best thing of it is that it works for all devices in your network! No matter what kind of it. PCs, smartphones, tablets and also Smart-TVs. So, I analyzed the traffic from the TV and added all the unwanted domains to the blacklist in Pi-Hole. This is only necessary, if the domain which you want to block is not already included in the default list that comes with Pi-Hole.


After everything is enabled and your TV (or other device) is used for a while, the list of  ‘Top Blocked Domains’ should fill up. You can clearly see the domains entered entered in the Blacklist showing up, after using the TV for a while.


Pi-Hole is now running stable and reliable on my Pi since a few months. It does not use a lot of resources and it does not interfere with any other applications installed next to it, so for me, it is definitely recommendable.