Solved

Telnet using PHP

Posted on 2001-07-30
7
1,053 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
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

 
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

695 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