<?php
# main
    
    if ( ! isset( $_GET['check'] ) ) {
        echo "ERROR: NO IP-GIVEN. ### USAGE: SET ?check=IPv4";
        exit;
    }
    $_GET['check'] = ip2dec( trim( $_GET['check'] ) );
    if ( false === $_GET['check'] ) {
        echo "<pre>ERROR: Not a IPv4-Address: " , $ipOut , "</pre></body></html>";
        exit;
    }

    $ips = explode( "\n" , `/opt/fwlist` );
    foreach( $ips as $ip ) {
        $ip = trim( $ip );
        if( $ip ) {
            if( false === strpos( $ip , '/' ) ) {
                $ip      = $ip . '/32';
                $firstIP = ip2dec( $ip );
                $lastIP  = $firstIP;
                $netMask = 32;
            } else {
                list ( $firstIP, $netMask ) = explode( '/' , $ip );
                $firstIP = ip2dec( $firstIP );
                $lastIP  = $firstIP + pow( 2 , 32-$netMask );
            }
            if( $_GET['check'] >= $firstIP && $_GET['check'] <= $lastIP ) {
				header( 'Content-Type: text/plain' );
                echo 'BLOCKED';
                exit;
            }
        }
    }
    header( 'Content-Type: text/plain' );
    echo 'NOT BLOCKED';
    exit;

function ip2dec( $ip ) {
    return sprintf( '%u', ip2long( $ip ) );
}