既然过程都描述出来了
写就简单了
锻炼下自己的php

解决方案 »

  1.   


    function mask2bin( $n ) {
    $n = intval($n);
    if ( $n < 0 || $n > 32 ) die('error submask');
    return str_repeat("1", $n).str_repeat("0",32-$n);
    }function revBin( $s ) {
    $p = array( '0', '1', '2' );
    $r = array( '2', '0', '1' );
    return str_replace( $p, $r, $s );
    }function execIp( $str ) {
    list($ip, $m) = explode("/", $str);
    $bIp = decbin( ip2long($ip) );
    $bSub = mask2bin(20);
    $sIp = $bIp & $bSub;
    $eIp = $bIp | revBin($bSub);
    print " ip : ".$sIp." - ".$eIp;
    }$str = "192.168.1.5/20";
    execIp( $str );