Solved

Telnet using PHP

Posted on 2001-07-30
7
1,051 Views
Last Modified: 2012-06-21
OK, I've seen alot of examples on how to use php for telnet purposes... some work... and some don't... my main problem is that the php script hangs on any version of fgets() or read() no matter what I tried (obviously I haven't tried the correct way :0). I have read the manual when it comes to sockets and it still doesn't work the way I think it should.

Unlike most of the examples out there I don't want to use PHP to allow the user to telnet into a server. Instead, I want my PHP script to connect to a server, send a preformatted command ( such as 'ls') and record the results, and close the connection. After that, I want to echo the results back to the webpage.

So here is the logic that I've tried:
1. Creating Socket (using socket() or fsockopen())
2. Connecting to Server (using connect())
3. Sending Username (using write() or fputs())
4. Sending Password (using write() or fputs())
5. Sending 'ls' Command (using write() or fputs())
6. Retrieving Directory Listing (using read or fgets())
7. Disconnecting from server (using close() or fclose())
8. Echo directory listing as webpage (using echo())

My ultimate goal is to automate a search feature ('grep') with a simple parameter, and return the results. This would save so much time, as my fellow workers use telnet to grep many different servers to perform advanced tech support by searching logs and perform cable modem provisioning.

Any help would be appreciated.

Robert Knepp
Adelphia Communications
Knowledge Engineer
0
Comment
Question by:rknepp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 3

Expert Comment

by:superschlonz
ID: 6336345
You could use rsh for executing the commands on the other machines.

Another way is using expect with telnet to execute the commands.

You can use both of them with popen( "command" ).
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6336387
If you use rsh you have to setup the other machines correctly (/etc/hosts.equiv, ~/.rhosts). Then you should be able to execute commands from a shell:

> rsh otherhost ls -la

And from php:

$pipe = popen( "rsh otherhost ls -la", "r" );
...read with fgets
0
 
LVL 2

Expert Comment

by:curri
ID: 6337064
I don't know how to use sockets either (will probably try later :) but wanted to point you towards expect. It is a program/language designed to do things like that. Essentially you start a telnet program and send keys to it, just as if you were typing, and read from it.

I haven't used it under windows, but it works great under unix/linux. If you're on  a linux system do man expect.

Orlando
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Expert Comment

by:Moondancer
ID: 6419221
It's time to clean up this topic area and that means taking care of this question. Your options at this point are:

1. Award points to the Expert who provided an answer, or who helped you most. Do this by clicking on the "Accept Comment as Answer" button that lies above and to the right of the appropriate expert's name.

2. PAQ the question because the information might be useful to others, but was not useful to you. To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

3.  Ask Community Support to help split points between participating experts.  Just comment here with details.

4.  Delete the question because it is of no value to you or to anyone else.  To use this option, you must state why the question is no longer useful to you, and the experts need to let me know if they feel that you're being unfair.

If you elect for option 2, 3 or 4, just post comment with details here and I'll take it from there.  We also request that you review any other open questions you might have and update/close them.  Display all your question history from your Member Profile to view details.

PLEASE DO NOT AWARD THE POINTS TO ME.

____________________________________________



Hi Experts:

In the event that the Asker does not respond, I would very much appreciate your opinions as to which Expert ought to receive points (if any) as a result of this question.  Likewise, you can also suggest that I PAQ or delete the question.

Experts, please do not add further "answer" information to this question.  I will be back in about one week to finalize this question.

Thank you everyone.

Moondancer :)
Community Support Moderator @ Experts Exchange

P.S.  REGARDING POINTS, Guidelines and more:  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp  
0
 

Author Comment

by:rknepp
ID: 6419473
I'll choose option #3 as I do believe that everyone who posted comments had valid points that I did look into.

The reason I didn't choose a comment for an answer is this:

Since Linux (and PHP) are open source, it's different between different users (making questions like mine hard to answer)... this being the case no one really knows whether anything will work or not... they just have guesses... this is deserving of points just not all of them...
0
 

Author Comment

by:rknepp
ID: 6419492
I'll actually accept my own answer:

PHP and sockets just don't work most of the time... maybe if they got socket_get_status to work correctly it would...

So I scrapped the whole idea and recoded SSH2... :-)
0
 
LVL 1

Accepted Solution

by:
Moondancer earned 0 total points
ID: 6646190
I've refunded your points for this question and moved it at zero points to our PAQ to close it.
Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question