Beispiel #1
0
function dnpt($ext_ip, $ext_prefix, $int_prefix)
{
    $debug = false;
    // This is not a complete solution!!!!!!!!!!!!!!!!!!!!!!!!!!
    $ext_prefix = str_replace(":", "", $ext_prefix);
    $int_prefix = str_replace(":", "", $int_prefix);
    // hehe
    $sauce = hexdec(split(":", $ext_ip)[4]);
    $ext_c = icmpChecksum(hex2bin($ext_prefix));
    $int_c = icmpChecksum(hex2bin($int_prefix));
    if ($debug) {
        print_r(unpack('n', $int_c));
    }
    $diff = unpack('n', $ext_c)[1] - unpack('n', $int_c)[1];
    if ($diff < 0) {
        $diff = 0xffff + $diff;
    }
    $diff = $sauce - $diff;
    if ($debug) {
        print bin2hex($ext_c);
        print "\n";
        print bin2hex($int_c);
        print "\n";
        print dechex($diff);
        print "\n";
    }
    $out = split(":", $ext_ip);
    $out[4] = dechex($diff);
    $out = join($out, ":");
    return $out;
}
Beispiel #2
0
        $data .= "";
    }
    $bit = unpack('n*', $data);
    $sum = array_sum($bit);
    while ($sum >> 16) {
        $sum = ($sum >> 16) + ($sum & 0xffff);
    }
    return pack('n*', ~$sum);
}
// Making the package
$type = "";
$code = "";
$checksum = "";
$identifier = "";
$seqNumber = "";
$data = "Scarface";
$package = $type . $code . $checksum . $identifier . $seqNumber . $data;
$checksum = icmpChecksum($package);
// Calculate the checksum
$package = $type . $code . $checksum . $identifier . $seqNumber . $data;
// And off to the sockets
$socket = socket_create(AF_INET, SOCK_RAW, 1);
socket_connect($socket, "www.google.com", null);
// If you're using below PHP 5, see the manual for the microtime_float
// function. Instead of just using the microtime() function.
$startTime = microtime(true);
socket_send($socket, $package, strlen($package), 0);
if (socket_read($socket, 255)) {
    echo round(microtime(true) - $startTime, 4) . ' seconds';
}
socket_close($socket);