• How to blacklist by IP (ModuleOverridePlayBlackListIP)

    This article describes how to use the ModuleOverridePlayBlackListIP module to override play and blacklist (refuse connection) by IP address.

    Note: This module has been removed from the Wowza Module Collection because the same functionality has been added to Wowza Streaming Engine™ software. See Playback Security > Client Restrictions for more information about this functionality in Wowza Streaming Engine. The source code has been retained here for reference.
    package com.wowza.wms.example.module;
    import com.wowza.wms.amf.*;
    import com.wowza.wms.application.IApplicationInstance;
    import com.wowza.wms.client.*;
    import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
    import com.wowza.wms.module.*;
    import com.wowza.wms.request.*;
    import com.wowza.wms.rtp.model.RTPSession;
    
    public class ModuleOverridePlayBlackListIP extends ModuleBase {
    	
    	private String[] ipList = null;
    	
    	public void onAppStart(IApplicationInstance appInstance) {
    		ipList = appInstance.getProperties().getPropertyStr("IpList").toLowerCase().split(",");
    	}
    	
    	public void play(IClient client, RequestFunction function,
    	        AMFDataList params) {
    		getLogger().info("Overriding Play");
    		
    		boolean reject = false;
    			
    		try 
    		{
    		String clientIP = client.getIp();
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = true;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = false;
    		}
    		if (reject)
    		{
    			getLogger().info("Client Rejected. IP: " + client.getIp());
    			sendClientOnStatusError(client, "NetStream.Play.Failed", "The client IP was rejected");
    		} 
    		else
    		{			
    			ModuleCore.play(client, function, params);	
    		}		
    	}
    	
    	public void onHTTPSessionCreate(IHTTPStreamerSession httpSession)
    	{
    		boolean isGood = true;
    		
    		String clientIP = httpSession.getIpAddress();		
    		boolean reject = false;
    		
    		try 
    		{
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = true;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = false;
    		}
    		if (reject)
    		{
    			httpSession.rejectSession();
    			getLogger().info("HTTP Client Rejected. IP: " + clientIP);
    		} 		
    	}
    	
    	public void onRTPSessionCreate(RTPSession rtpSession)
    	{
    		boolean isGood = true;
    		
    		String clientIP = rtpSession.getIp();		
    		boolean reject = false;
    		
    		try 
    		{
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = true;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = false;
    		}
    		if (reject)
    		{
    			rtpSession.rejectSession();
    			getLogger().info("RTSP Client Rejected. IP: " + clientIP);
    		}
    	}
    }
    Add this Module last in the Modules list at /conf/[app-name]/Application.xml.
    <Module>
    	<Name>ModuleOverridePlayBlackListIP</Name>
    	<Description>ModuleOverridePlayBlackListIP</Description>
    	<Class>com.wowza.wms.example.module.ModuleOverridePlayBlackListIP</Class>
    </Module>
    Add the following property to the Properties list at the bottom of Application.xml.

    <Property>
    	<Name>IpList</Name>
    	<Value>192.168.1.2,192.168.1.3</Value>
    </Property>

    Wowza media server software and all components, including modules, source code, and other related items offered on this page, are copyrighted (c) 2006-2014 by Wowza Media Systems, LLC, all rights reserved, and are licensed pursuant to the Wowza Media Software End User License Agreement.
    Originally Published: 09-13-2012.
    Updated: For Wowza Streaming Engine 4.2 on 06-23-2015.

    If you're having problems or want to discuss this article, post in our forum.