1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?php
$host = "127.0.0.1";
$port = 3306;
$timeout = 5;
echo "trying to connect to $host on port $port\n";
$testcon = @fsockopen ($host, $port, $errno, $errstr, $timeout);
if(!$testcon)
die("database unavailable: $errno: $errstr\n");
else
{
echo "connection successful under $timeout seconds\n";
echo "quit connection\n";
$in = fread($testcon,4096);
echo "server says:$in\n";
//login string
$out = array( 0x26,0x00,0x00,0x01, //packet length 38 bytes (without this 4 byte header // packet no.1
0x85,0xa6,0x03,0x00,
0x00,0x00,0x00,0x01,
0x08,
0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00, 0x00,0x00,0x00,
0x66,0x69,0x66,0x69,0x00, //username 'fifi'
0x00); //no password
foreach($out as $o)
{
fputs($testcon,chr($o),1);
}
$in = fread($testcon,4096);
echo "server says:$in\n";
//logout command
$out = array(0x01,0x00,0x00,0x00,0x01);
foreach($out as $o)
fputs($testcon,chr($o),1);
fclose($testcon);
}
?> |
Partager