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.

Get the Broadcast Technology Newsletter

Sign up for the email newsletter about media and technology. Sent irregularly. No spam.

I'm Anthony Eden, and I'm a IT Professional, Broadcast Technician, Software Developer, and Solutions Engineer. I've been working in broadcast media since 2008, and developing software and websites for just as long. Right now, I provide freelance services through Media Realm - in particular, to the media and not-for-profit industries.

Follow Anthony on Twitter: @anthony_eden