It’s sometimes necessary to block listeners in certain geographical regions from listening to your Internet stream. There may be international right issues, such as with The Games. Thankfully, Icecast Streaming Media Server provides a way to enable geo-blocking.

To setup the Icecast geo-blocking, there’s three components we need to setup:

  1. PHP Script to issue block/allow commands
  2. GeoIP Database
  3. Icecast.xml mount configuration

The logic for blocking/allowing listeners can be handled by any external application, but I’ve found it easiest to do this with PHP. This sample script will check the client’s IP address against a whitelisted set of IP address subnets. Only white-listed clients will be able to connect.

You’ll need a list of IPv4 addresses to whitelist. You can download the free Maxmind GeoIP Lite database and format it as you need. I used some basic find-and-replace logic to turn it into an array. Here’s an example:

Any Icecast mount can be setup to check connections against this PHP script. However, you can’t set this up on relays. Here’s an example mount configuration:

Once you restart the Icecast server, any client whose IP address falls outside the whitelisted range will be unable to connect. They’ll get a HTTP 403 Forbidden message and the connection will be refused.