• How to limit playback by IP address (ModuleOverridePlayRestrictIP)

    The following example overrides playback and limits Flash clients to specific IP addresses. Handling for HTTP and RTSP clients has been added as well.

    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 ModuleOverridePlayRestrictIP 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 = true;
    			
    		try 
    		{
    		String clientIP = client.getIp();
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = false;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = true;
    		}
    		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 = true;
    		
    		try 
    		{
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = false;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = true;
    		}
    		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 = true;
    		
    		try 
    		{
    		for (int i = 0; i < ipList.length; i++)
    		{ 
    			if (clientIP.equalsIgnoreCase(ipList[i].trim()))
    			{
    				reject = false;
    				break;
    			}
    		} 
    		} 
    		catch(Exception ex)
    		{
    			reject = true;
    		}
    		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>ModuleOverridePlayRestrictIP</Name>
    	<Description>ModuleOverridePlayRestrictIP</Description>
    	<Class>com.wowza.wms.example.module.ModuleOverridePlayRestrictIP</Class>
    </Module>
    Add this 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: 10-03-2010.
    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.