I trying to create a telnet like program base on web page. Is there anyone have example about this ?
Sorry for my poor English.
I've seen these written in Java before, but I don't think you can do it in PHP.....feel free to prove me wrong..
There is much more to telnet than meets the eye. There is no way for you to open up a socket, for example, and simply print to it. Telnet protocol uses some control characters. The best way would be to use Perl and its Net::Telnet module (available from CPAN).
... and I say yes, you can.
PHP can open a socket, but that's not even necessary to do a telnet client in PHP.
PHP can pass commands to the system, and it can read standard output. What more do you need? All telnet is, is a method to enter commands to the system and read standard output.
I don't have any examples to show you, but I would recommend going to the documentation on the PHP site and studying the following PHP functions:
All of the network functions
All of the posix_* functions
All of the filesystem functions
By the time you are done, you will realize PHP has a very rich set of system functions to accomplish pretty much anything on the server. Be careful; anyone with access to your 'telnet client' PHP page can own your system.
>>PHP can open a socket, but that's not even necessary to do a telnet client in PHP.
>>What more do you need? All telnet is, is a method to enter commands to the system and read standard output.
That is limited to localhost. Telnet by all means is to connect to remote host.
>>The best way would be to use Perl and its Net::Telnet module (available from CPAN).
I would agree with dwarf - "The BEST WAY".
But, if you were using linux, couldn't you use the pass_thru (I think) function to do a system call to telnet, and then display and pass input, I know you could get it display, but I suppose the big thing would be to actually give input to the telnet program, and have it pass it.
There's a beginning of a phptelnet thingy here:
Here's the description from the web site:
"Pcom is a PHP-driven webtelnet, that is a web interface to execute shell commands/external programs on a server. Obviously there are limitations, derived mainly by security limitations on the webserver (ie safe_mode in php). There is also a limitation on the program function itself, because you can only use non-interactive commands: you can launch a command or a program that doesn't need user interaction, but you cannot use something like lynx or irc (you can onlylaunch an interactive application in background, driving it automatically by arguments and/or scripts -where possible-). Remember that you can only launch a command, you don't drive a real shell. So, if you launch a ping it will go forever because you cannot take back the control on the stdin, while launching a traceroute you should get back control and output of the command because it terminates itself without user interaction. "
I haven't tried it but I've been tempted 'cause I don't like doing telnet stuff.
From the day we're born, we're running out of time.
Thank you very much for all of your answer. I see some point to go on my work now.
>>That is limited to localhost. Telnet by all means is to connect to remote host.
...and once you are connected to localhost, all it takes to telnet elsewhere is to enter the command "telnet [otherhost]" and view the standard output.
I don't see the problem here.
July 10th, 2000, 02:48 AM
>>all it takes to telnet elsewhere is to enter the command "telnet [otherhost]" and view the standard output.
>>I don't see the problem here.
The problem is, you can't even run that "telnet" command.
Even Joel's Pcom is a PHP-driven webtelnet suggestion is not a real solution. That's still limited to localhost which absolutely defeat the purpose of Telnet.
All your PHP ways in this thread is just sending commands and talking to the local system. Calling it Telnet is a misleading term. It should be called "commander" instead.
With all being said, I am not saying PHP can't perform the task, but Net::Telnet is definitely a way better choice, if someone comes up with a real solution, I'd be glad to hear. Note, I am talking about a web-based telnet interface that enables you to connect ANYWHERE thru Telnet protocol.
July 10th, 2000, 12:08 PM
hmm.. ya ain't gettin' the point here!
ya can open a process telnet(ya know DA application, da same one yer usin' in shell?) and write stuff there. Like when ya do a some formmail script that uses sendmail and not mail() there ya open a sendmail process and write data there...
July 10th, 2000, 06:25 PM
>>ya can open a process telnet and write stuff there.
>>Like when ya do a some formmail script that uses sendmail
The Perl way is a piece of cake. If you don't have an example of Net::Telnet using PHP, then you should be the one not gettin the point here.
In case PHP can't perform such task, you don't have to defense PHP, there is always an alternative -> Net::Telnet. Enough said.
July 10th, 2000, 10:44 PM
Another problem: you cannot simply run telnet, then tell it to do something, capture the output and display it to the user. Telnet waits its commands from the standard input, and I think that in its case is the shell.
Perl is the easiest way here. Note that PHP was never meant for something like this, while Perl was (sort of).
August 16th, 2000, 09:30 AM
This may be oversimply-fying the question, but this is what I use for our web site:
telnet://xxx.xxx.xxx.xxx/ (as a link)
Granted, I assume that our clients are either running Windows NT or Win9x.