<?php
function calcchecksum($packet)
{
if (strlen($packet)%2!=0)
{
$packet.="\x00";
}
$wordrow=unpack("n*",$packet);
$checksum=array_sum($wordrow);
while ($checksum>>16)
{
$checksum=($checksum>>16)+($checksum&0xffff);
}
$packedsum=pack("n",~$checksum);
return $packedsum;
}
function incsequenceno($sequenceno)
{
if (ord($sequenceno{1})==255)
{
return chr(ord($sequenceno{0})+1)."\x00";
}
else
{
return $sequenceno{0}.chr(ord($sequenceno{1})+1);
}
}
if (isset($_SERVER['argv'][1]))
{
$host=$_SERVER['argv'][1];
}
else
{
$host="localhost";
}
$socket=socket_create(AF_INET,SOCK_RAW,1);
socket_bind($socket,0);
socket_connect($socket,$host,NULL);
$type="\x08";
$code="\x00";
$identifier="\x00\x00";
$sequenceno="\x00\x00";
for ($x=0;$x<4;$x++)
{
$data="";
for ($y=0;$y<7;$y++)
{
$data.=chr(rand(0,255));
}
$data.="\x00\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36\x37";
$checksum="\x00\x00";
$sequenceno=incsequenceno($sequenceno);
$checksum=calcchecksum($type.$code.$checksum.$identifier.$sequenceno.$data);
$packet=$type.$code.$checksum.$identifier.$sequenceno.$data;
socket_write($socket,$packet);
}
socket_shutdown($socket);
socket_close($socket);
?>