• Resolved praveen369gen

    (@praveen369gen)


    Hello Folks,
    I have recently installed ninja firewall and I want to whitelist all JetPack IPs. Is it possible to whitelist IP CIDR and AS numbers in ninja, like in cloudflare?

    How to whitelist all IPs in the range 192.0.[64-127].[1-254]?

    • This topic was modified 2 years, 9 months ago by praveen369gen.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author nintechnet

    (@nintechnet)

    CIDR and ASN are only available in the premium WP+ Edition (there’s also an option to whitelist Jetpack and some payment gateways like Paypal etc).

    In the free WP Edition, you need to use the .htninja script.

    Thread Starter praveen369gen

    (@praveen369gen)

    Thanks for the response. I have already created the .htninja file and the following code as well. Do you think this enough? Is there any way I can whitelist ASN via the .ninja file?

    // Allow JetPack CIDR (IPv4 **only**):
    
    $cidr_array = array('192.0.64.0/18');
    // Loop through the array:
    foreach ( $cidr_array as $cidr ) {
       // Check IP vs CIDR:
       if ( ipCIDRCheck( $_SERVER['REMOTE_ADDR'], $cidr ) ) {
          // IP matches, allow it:
          return 'ALLOW';
       }
    }
    
    function ipCIDRCheck( $IP, $CIDR ) {
       list ( $subnet, $bits ) = explode( '/', $CIDR );
       $ip = ip2long( $IP );
       $subnet = ip2long( $subnet );
       $mask = -1 << ( 32 - $bits );
       $subnet &= $mask;
       return ( $ip & $mask ) == $subnet;
    }
    Plugin Author nintechnet

    (@nintechnet)

    That should work.

    You can’t use the .htninja to check AS numbers, because you’d need a database. In the WP+ Edition, we are using two ASN databases, one for IPv4 and one for IPv6.

    Thread Starter praveen369gen

    (@praveen369gen)

    Thank you so much. I am happy with ninja firewall.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to whitelist CIDR and ASN?’ is closed to new replies.