PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 17th, 2003, 10:40 AM
Snowfruit Snowfruit is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Ireland
Posts: 11 Snowfruit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question PHP -> Telnet -> PHP

Question:

Is it possible to setup a telnet connection to another server from within a PHP script and then start another PHP script on the remote server?

Reply With Quote
  #2  
Old January 17th, 2003, 06:44 PM
Brian Rosner Brian Rosner is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Denver, CO
Posts: 34 Brian Rosner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to Brian Rosner Send a message via AIM to Brian Rosner Send a message via Yahoo to Brian Rosner
Yeah, I know it's possible. I believe you will want to make use of PHP's fsockopen() function. It works very similar to other stream functions like fopen().

Reply With Quote
  #3  
Old January 17th, 2003, 10:06 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
Opening the telnet connection shouldn't be too difficult....but unless you're using something like SSH (and you can use that to execute a php file), I don't think you'll be able to execute another PHP script through the connection. If you can, I'd certainly like to know how!

Of course, this is all speculation on my part, so I could be wrong. But for the Telnet connection, use fsockopen() like Brian suggested.
__________________
Jeb.

AIM: JebediahMc - PM Me - E-Mail Me


Reply With Quote
  #4  
Old January 18th, 2003, 12:11 AM
Brian Rosner Brian Rosner is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Denver, CO
Posts: 34 Brian Rosner User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to Brian Rosner Send a message via AIM to Brian Rosner Send a message via Yahoo to Brian Rosner
Well, I was thinking abit more on this topic that may help. You could create your own little program in basically any language that supports sockets and have it create a socket and listen on port. Then have your PHP script access it using the fsockopen() function and send a request for a PHP that would then be executed through the program listening on port. Grab the output and spit it back down to the PHP script.

Heck, you could even have PHP do everything. Create a PHP script to run through the CLI using PHP sockets, experimental , and have PHP execute your other PHP script. But that would basically be crazy.

Why exactly do you want to do this? What is it for?

Last edited by Brian Rosner : January 18th, 2003 at 12:13 AM.

Reply With Quote
  #5  
Old January 20th, 2003, 04:17 AM
Snowfruit Snowfruit is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Location: Ireland
Posts: 11 Snowfruit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Ok heres what i want it to do:

I have a php script that generates a .html file every time we update a links list. Now I need this file to be coppied to about 300 sites across 2 different servers. I figured out how to copy it to all the sites on the same server as the script, but i can't seem to figure out how to get the 1st script to start the 2nd script on the second server. At the moment I have to run the sript on the second server manually - which is not ideal but will do if I can't find another way to run it...

Any hints?

Reply With Quote
  #6  
Old January 21st, 2003, 09:44 PM
Jeb. Jeb. is offline
"l33t? What's l33t?"
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 51 Jeb. User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via AIM to Jeb.
Wow....so you have one global HTML file for your links list, which 300 sites access?

Perhaps for the sake of 'ease of use' you could simply write one universal script that grabs the HTML file from server 1. Then, use the script where you need to get the link list.

It would be easier than updating it across 300 sites.

However, the only other method I know of would be to do what brian said: Write a program to listen on a particular socket, and then write another PHP script to connect to this socket and perform a function. However, this is dangerous because anybody could connect to this socket and play with your file.

Other than that, or use a global database for your link lists, I can't see an easy way.

-J.

Reply With Quote
  #7  
Old February 22nd, 2004, 08:15 AM
BIG_Nicky BIG_Nicky is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 BIG_Nicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
<?
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).c hr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).c hr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).c hr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).c hr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).c hr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).c hr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).c hr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).c hr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).c hr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).c hr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).c hr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).c hr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).c hr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).c hr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).c hr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).c hr(0xFF).chr(0xFC).chr(0x21);

Reply With Quote
  #8  
Old February 22nd, 2004, 08:19 AM
BIG_Nicky BIG_Nicky is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 BIG_Nicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
$fp=pfsockopen("127.0.0.1",23);

fputs($fp,$header1);
sleep(1);
fputs($fp,$header2);
sleep(1);

fputs($fp,"user\r");
sleep(1);
fputs($fp,"pass\r");
sleep(1);
fputs($fp,"su\r");
sleep(1);
fputs($fp,"root.pass\r");
sleep(1);
fputs($fp,"ifconfig\r");
fputs($fp,"echo dat lupt|wall\r");
sleep(1);

$output=fread($fp,128);
$stat=socket_get_status($fp);
$output.=fread($fp, $stat["unread_bytes"]);

$output = explode("\n", $output);
unset($output['0']);
$output = implode("\n", $output);

$output = str_replace("\n", "<br>", $output);
echo $output;
fclose($fp);
?>


sorry, i must split the code, to much text for one post, this works fine for me, the header is the only difficult thing.

Reply With Quote
  #9  
Old July 9th, 2004, 05:45 PM
bcoffin bcoffin is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 bcoffin User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Big Nicky? Help?

I'm using your code (above) and it works like a charm except the $output truncates after 122 lines.
Any idea why it might be doing that? Can you maybe suggest a solution? I know that there's more to be read,
it even stops in the middle of the line, which caused me to suspect there's a memory limit or time-out..

Help?

Benny

Reply With Quote
  #10  
Old March 6th, 2008, 03:56 AM
stender stender is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 stender User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 53 sec
Reputation Power: 0
Hi I am wanting to telnet to a server and port and then to loop through a list (circa 2m records) in 1 table and store the results in another table, but also to limit it to a certain amount a day.
Can anyone help.

Reply With Quote
  #11  
Old April 11th, 2011, 09:16 PM
prog_eve prog_eve is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 1 prog_eve User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m
Reputation Power: 0
Quote:
Originally Posted by BIG_Nicky
<?
$header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).c hr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).c hr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).c hr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).c hr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).c hr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).c hr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).c hr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).c hr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).c hr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).c hr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).c hr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).c hr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).c hr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).c hr(0xF0);
$header2=chr(0xFF).chr(0xFC).chr(0x01).chr(0xFF).c hr(0xFC).chr(0x22).chr(0xFF).chr(0xFE).chr(0x05).c hr(0xFF).chr(0xFC).chr(0x21);


Could anyone tell me what's this code mean?
Thanks B4

Reply With Quote
  #12  
Old January 31st, 2012, 07:13 AM
mb0000 mb0000 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2012
Posts: 1 mb0000 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 38 sec
Reputation Power: 0
header variables

Quote:
Originally Posted by prog_eve
Could anyone tell me what's this code mean?
Thanks B4


It's preamble / integral part of the TELNET protocol. I was curious myself, so here's a simple decode:
PHP Code:
// TELNET commands. From tools.ietf.org/html/rfc854  and also (IANA website)/assignments/telnet-options
$header1=    chr(0xFF).chr(0xFB).chr(0x1F).    // 0xFF 0xFB 0x1F - WILL command - NEGOTIATE-WINDOW-SIZE
        
chr(0xFF).chr(0xFB).chr(0x20).    // 0xFF 0xFB 0x20 - WILL command - TERMINAL-SPEED
        
chr(0xFF).chr(0xFB).chr(0x18).    // 0xFF 0xFB 0x18 - WILL command - TERMINAL-TYPE
        
chr(0xFF).chr(0xFB).chr(0x27).    // 0xFF 0xFB 0x27 - WILL command - NEW-ENVIRON
        
chr(0xFF).chr(0xFD).chr(0x01).    // 0xFF 0xFD 0x01 - DO command - ECHO
        
chr(0xFF).chr(0xFB).chr(0x03).    // 0xFF 0xFB 0x03 - WILL command - SUPPRESS-GO-AHEAD
        
chr(0xFF).chr(0xFD).chr(0x03).    // 0xFF 0xFD 0x03 - DO command - SUPPRESS-GO-AHEAD
        
chr(0xFF).chr(0xFC).chr(0x23).    // 0xFF 0xFC 0x23 - WON'T command - X-DISPLAY-LOCATION
        
chr(0xFF).chr(0xFC).chr(0x24).    // 0xFF 0xFC 0x24 - WON'T command - ENVIRONMENT
        
chr(0xFF).chr(0xFA).            // 0xFF 0xFA ... - SB command
                            
chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).      // NEGOTIATE-WINDOW-SIZE <Width1>=0 <Width0>=80 <Height1>=0 <Height0>=24
        
chr(0xFF).chr(0xF0).            // 0xFF 0xF0 - SE command
        
chr(0xFF).chr(0xFA).            // 0xFF 0xFA ... - SB command
                            
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).    // TERMINAL-SPEED - 38400,38400
        
chr(0xFF).chr(0xF0).            // 0xFF 0xF0 - SE command
        
chr(0xFF).chr(0xFA).            // 0xFF 0xFA ... - SB command
                            
chr(0x27).chr(0x00).    // NEW-ENVIRON <IS> <empty>
        
chr(0xFF).chr(0xF0).            // 0xFF 0xF0 - SE command
        
chr(0xFF).chr(0xFA).            // 0xFF 0xFA ... - SB command
                            
chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).  chr(0x52).chr(0x4D).    // TERMINAL-TYPE: <IS> XTERM
            
chr(0xFF).chr(0xF0);            // 0xFF 0xF0 - SE command
$header2=    chr(0xFF).chr(0xFC).chr(0x01).    // 0xFF 0xFC 0x01 - WON'T command - ECHO
        
chr(0xFF).chr(0xFC).chr(0x22).    // 0xFF 0xFC 0x22 - WON'T command - LINEMODE
        
chr(0xFF).chr(0xFE).chr(0x05).    // 0xFF 0xFE 0x05 - DON'T command - STATUS
        
chr(0xFF).chr(0xFC).chr(0x21);    // 0xFF 0xFC 0x21 - WON'T command - TOGGLE-FLOW-CONTROL 


Summarised, they're part of the negotiation between a TELNET client and a TELNET server each telling the other what they are and can / cannot do. I'm assuming the original poster BIG_Nicky culled them from a real session from an xterm window.

(As a new joiner, I can't post URIs, so you'll have to work out where IETF and IANA are )

Hope this helps

Reply With Quote
  #13  
Old March 1st, 2012, 06:22 AM
Struble2010 Struble2010 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 Struble2010 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 18 sec
Reputation Power: 0
Appreciate the post. Thanks

Reply With Quote
  #14  
Old March 2nd, 2012, 02:33 AM
Donald24 Donald24 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 7 Donald24 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 26 m 38 sec
Reputation Power: 0
Haha, I think I'll just try EasyPHP, that is supposed to have everything covered. Still stumps me though why the stupid thing shows source code instead of the execution of a simple script php.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP -> Telnet -> PHP


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap