BeBop |
03-26-2005 03:21 PM |
php sockets, HELP -fsockopen
Ok, how would i connec to telnet using PHP with fsockopen, and then execute commands on telnet and get the returned data back....
I've tried to use socket_create but its not enabled on my php build so i dont wanna mess with it.
I've tried to use some examples on php.net but they'll only return the first line of whats displays (im connecting to teamspeaks telnet, so it returns [TS]) then a line break, and then thats it... i wont execute any of the commands i put in... hers what ive tried...
This is an example ive used from PHP.net's website ( http://www.php.net/manual/en/function.fsockopen.php )
PHP Code:
<?php
# This is the difficult part, the Telnet header
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).
chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).
chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).
chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).
chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).
chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).
chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).
chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).
chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).
chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).chr(0xFC).
chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).chr(0xFF).chr(0xFC).chr(0x21);
# connecting
$fp=fsockopen("127.0.0.1",51234);
# sending the Telnet header
fputs($fp,$header1);
usleep(125000);
fputs($fp,$header2);
usleep(125000);
# login
fputs($fp,"slogin superadmin pass.word\r");
usleep(125000);
//fputs($fp,"users.pass\r");
//usleep(125000);
# root looks nice
fputs($fp,"dbserverlist");
usleep(125000); # takes some time, we had to wait
//fputs($fp,"root.pass\r");
# some tests
//fputs($fp,"ifconfig\r");
//fputs($fp,"echo year telnet php connect works|wall\r");
# we had to wait
usleep(125000);
# show the output
do
{
$output.=fread($fp, 80); // read line by line, or at least small chunks
$stat=socket_get_status($fp);
}
while($stat["unread_bytes"]);
$output = str_replace("\n", "<br>", $output);
echo $output;
fclose($fp);
?>
The username and password for the superadmin account are different but this is just for the example im using to try and connect and execute a dbserverlist command. The only output returned is:
Thanks in advance!
|