Go Back   Novahq.net Forum > Computers > Web design and Programming
FAQ Community Calendar Today's Posts Search

Web design and Programming Discuss website creation and other programming topics.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-26-2005, 03:21 PM
BeBop is offline BeBop
Registered User

Join Date: Jun 2002
Posts: 600

Send a message via ICQ to BeBop Send a message via AIM to BeBop Send a message via Yahoo to BeBop
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!
__________________
- My: Drawings, rants, raves, my cat, designs, and everything else i want to put on the net.
Free Teamspeak servers: http://gamersnetwork.us/

Reply With Quote
  #2  
Old 03-26-2005, 03:49 PM
DevilDog#1 is offline DevilDog#1

Join Date: Jul 2002
Posts: 7,040

Checkout this link.
__________________








Quote:
If I don't do that doesn't mean I can't - DD#1
Reply With Quote
  #3  
Old 03-26-2005, 04:05 PM
BeBop is offline BeBop
Registered User

Join Date: Jun 2002
Posts: 600

Send a message via ICQ to BeBop Send a message via AIM to BeBop Send a message via Yahoo to BeBop
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.
__________________
- My: Drawings, rants, raves, my cat, designs, and everything else i want to put on the net.
Free Teamspeak servers: http://gamersnetwork.us/

Reply With Quote
  #4  
Old 03-26-2005, 04:11 PM
DevilDog#1 is offline DevilDog#1

Join Date: Jul 2002
Posts: 7,040

Check your PM please.
__________________








Quote:
If I don't do that doesn't mean I can't - DD#1
Reply With Quote
  #5  
Old 03-26-2005, 10:39 PM
BeBop is offline BeBop
Registered User

Join Date: Jun 2002
Posts: 600

Send a message via ICQ to BeBop Send a message via AIM to BeBop Send a message via Yahoo to 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....
__________________
- My: Drawings, rants, raves, my cat, designs, and everything else i want to put on the net.
Free Teamspeak servers: http://gamersnetwork.us/

Reply With Quote
  #6  
Old 03-26-2005, 11:01 PM
DevilDog#1 is offline DevilDog#1

Join Date: Jul 2002
Posts: 7,040

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.

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








Quote:
If I don't do that doesn't mean I can't - DD#1
Reply With Quote
  #7  
Old 03-26-2005, 11:50 PM
IcIshoot is offline IcIshoot

Join Date: Mar 2004
Location: Farmington Hills, MI
Posts: 1,473

Send a message via AIM to IcIshoot Send a message via MSN to IcIshoot Send a message via Yahoo to IcIshoot
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
Reply With Quote
  #8  
Old 03-27-2005, 05:41 PM
BeBop is offline BeBop
Registered User

Join Date: Jun 2002
Posts: 600

Send a message via ICQ to BeBop Send a message via AIM to BeBop Send a message via Yahoo to BeBop
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
__________________
- My: Drawings, rants, raves, my cat, designs, and everything else i want to put on the net.
Free Teamspeak servers: http://gamersnetwork.us/

Reply With Quote
  #9  
Old 03-27-2005, 05:50 PM
DevilDog#1 is offline DevilDog#1

Join Date: Jul 2002
Posts: 7,040

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

Let me know how it works out.
__________________








Quote:
If I don't do that doesn't mean I can't - DD#1
Reply With Quote
  #10  
Old 03-27-2005, 06:46 PM
BeBop is offline BeBop
Registered User

Join Date: Jun 2002
Posts: 600

Send a message via ICQ to BeBop Send a message via AIM to BeBop Send a message via Yahoo to 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
__________________
- My: Drawings, rants, raves, my cat, designs, and everything else i want to put on the net.
Free Teamspeak servers: http://gamersnetwork.us/

Reply With Quote
  #11  
Old 03-27-2005, 06:48 PM
DevilDog#1 is offline DevilDog#1

Join Date: Jul 2002
Posts: 7,040

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!
__________________








Quote:
If I don't do that doesn't mean I can't - DD#1
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DFX2 Error trying to activate: NETWORK SOCKETS blocked high_low_jack Tech Support 14 12-27-2009 02:50 PM
FSockOpen & SSH BeBop Web design and Programming 5 02-03-2006 10:53 PM
Php Help!! navysea| Web design and Programming 3 03-04-2005 06:27 PM
PHP-NUKE and PHP ~BLÃÐE~ phphq.Net Forums 9 01-19-2005 06:49 AM
Need Help Using PHP .DareDevil. Web design and Programming 15 08-11-2004 01:04 AM


All times are GMT -5. The time now is 01:40 PM.




Powered by vBulletin®