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:
PHP Script to issue block/allow commands
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 broadcast technician / software developer / technology solutions engineer. I've been working in broadcast media since 2008 (getting my start in Community Radio while still at school), and developing software and websites for just as long.
Right now, I work in the broadcast industry and provide some freelance services through Media Realm.