Jump to content

laie_techie

Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Contact Methods

  • Website URL
    http://

Profile Information

  • Gender
    Not Telling
  • Location
    O'ahu, Hawai'i, USA

laie_techie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. First step: translate 192.168.1.0/22 into something you can use as a mask. 192.168.1.0/22 means that the first 22 bits of the IP in question must be identical to the first 22 bits in the base IP. BTW, each octet of the IP can be at most 255, so your sample IP of 192.168.1.312 was invalid. Untested code: [code=php:0] // Expects $base_ip and $ip to be in dotted format function in_network( $base_id, $bit, $ip) { $base_ip = ip2long( $base_ip ); $test1 = $base_ip >> ( 32 - $bits ) $ip = ip2long($ip); $test2 = $ip >> (32 - $bits ); return $test1 == $test2; } if ( in_network('192.168.1.0', 22, '192.168.1.212') ) { echo "Same network!"; } else { echo "Different network!"; } [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.