Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   php sockets, HELP -fsockopen (https://novahq.net/forum/showthread.php?t=24129)

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($fp80);    // 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:
Code:

[TS]
Thanks in advance!

DevilDog#1 03-26-2005 03:49 PM

Checkout this link.

BeBop 03-26-2005 04:05 PM

the libraries for those functions arent installed ( dont know if my post made that clear or not )... thanks though... i tried using the socket_create() but it gave a Fatal error saying it was an undefined function.

DevilDog#1 03-26-2005 04:11 PM

Check your PM please. ;)

BeBop 03-26-2005 10:39 PM

Thanks ill try there later tonight, i was hopin P might know... he seems to be able to figure out all my problems lol....

DevilDog#1 03-26-2005 11:01 PM

Quote:

Originally posted by BeBop
Thanks ill try there later tonight, i was hopin P might know... he seems to be able to figure out all my problems lol....
He's busy nowadays for some reason. :rolleyes:

Let me know whatever comes out. I need to get that thing too. :D

IcIshoot 03-26-2005 11:50 PM

I would suggest that you take a look at the source code for the Teamspeak Block for php-nuke and see how they did it (which is how I often figure out how to do stuff)

I just checked the source code and they used fsockopen() too.

Here is how they got the player list, after all the connections have been made (note, $this refers to a class that is handling all the telnet work):

PHP Code:

$this->sendQuery($this->socket,"pl");

  
// read player info
  
$this->playerList = array();
  do {
    
$playerinfo fscanf($this->socket"%s %d %d %d %d %d %d %d %d %d %d %d %d %s %s");
    list(
$playerid$channelid$receivedpackets$receivedbytes$sentpackets$sentbytes$d$d$totaltime$idletime$d$d$d$s$playername) = $playerinfo;
    if(
$playerid != "OK") {
      
$this->playerList[$playerid] = array("playerid" => $playerid,
      
"channelid" => $channelid,
      
"receivedpackets" => $receivedpackets,
      
"receivedbytes" => $receivedbytes,
      
"sentpackets" => $sentpackets,
      
"sentbytes" => $sentbytes,
      
"totaltime" => $totaltime,
      
"idletime" => $idletime,
      
"playername" => $this->stripQuotes($playername));
    }
// end if
  
} while($playerid != "OK"); 

And fyi, I don't see any sign of the author setting up a header for the connection, The whole telnet process seems pretty straight forward.


IcI

BeBop 03-27-2005 05:41 PM

I think im gonna try a different class... i think i was doing something wrong which was why it wasnt working... i'll just ask on the team speak forums

DevilDog#1 03-27-2005 05:50 PM

OK OK try this link. First result looks VERY promising.

Let me know how it works out. ;)

BeBop 03-27-2005 06:46 PM

Hehe i figured it out on my own! The first thing I had was working fine, but the carriage return wasnt entering the information so it wasnt entering it :) had to use \n to get it to act as a 'enter' :) Everythings working good

DevilDog#1 03-27-2005 06:48 PM

Quote:

Originally posted by BeBop
Hehe i figured it out on my own! The first thing I had was working fine, but the carriage return wasnt entering the information so it wasnt entering it :) had to use \n to get it to act as a 'enter' :) Everythings working good
Cool! :)


All times are GMT -5. The time now is 07:50 AM.

Powered by vBulletin®