473,761 Members | 3,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Establish a connection telnet in PHP on a UNIX server

Hello,

I wish to establish a connection in language PHP on a UNIX server by telnet.
In fact, I would like :
- Connect to server by sending IP adress, login, password
- Send an order (example: LS - Al)
- Receive the result in a string
- Send an order (example: CD ..)
- Receive the result in a string
- Etc...

I am already at a advanced stage but I am not solved my problem completely.
I have actually 3 solutions:

Solution 1:
-----------
A program write with the sockets

//Function reading the flow
function lisflux($flux)
{
// waiting the first char
$Char = false;
while (!$Char) $Char = fgetc($flux);
$Output = $Char;

//Reading next chars
$Output. = fread($flux, 1024);

//Replace the carriage return
$Output = str_replace("\n ", " ", $Output);
return $Output;
}
$Socket = pfsockopen($Hos tName, $Port);

if (! $Socket)
{
echo 'Connetion refused : <br>';
echo strerror ($Socket) . '<br>';
}
else
{
// Header 1
fputs($Socket, $Header1);
lisflux($Socket );

//Header 2
fputs($Socket, $Header2);
echo lisflux($Socket );

//Writing the login
fputs($Socket, "login\r");
echo lisflux($Socket );

//Writing Passwd
fputs($Socket, "passwd\r") ;
echo lisflux($Socket );

//Writing the order
fputs($Socket, #Commande. "\r");
echo lisflux($Socket );
}

This solution works correctly but it not stable
- I can't modify the timeout which remains hopelessly fixed to 30s
- The returned flow is sometimes incorrect.
In fact, I make 2 times the same thing but I do not obtaint the same
result.
Sometimes, returned flow is truncated. Sometimes, it is correct.

Is somebody already wrote a functional program in PHP with the sockets for
telnet?
Solution 2:
-----------
Use CURL which is originally implemented in PHP.
I wrote a program in PHP with CURL library.
This program runs correctly for a connection HTTP, ftp...
On the other hand, I have no documentation and no example for a connection
telnet

Is somebody already wrote a functional program in PHP with the CURL library
?

Solution 3:
-----------
Use EXPECT library
I have downloaded EXPECT for Windows (I develop with EasyPHP)
But the documentation is completely incompéhensible

Is somebody already wrote a functional program in PHP with the EXPECT
library ?
Thank you by advance to answer on my email: rp*******@buyin gpack.com

Robert PADOVANO

Jul 17 '05 #1
1 6278
Robert PADOVANO <rp*******@buyi ngpack.com> wrote:
[fsockopen]
This solution works correctly but it not stable
- I can't modify the timeout which remains hopelessly fixed to 30s
http://php.net/pfsockopen
resource pfsockopen ( string hostname, int port [, int errno [, string
errstr [, int timeout]]])

Take a closer look at the last parameter :)
Is somebody already wrote a functional program in PHP with the sockets for
telnet?


You shouldn't be using telnet for this, this is what rsh (remote shell)
was introduced for. But even better maybe you can call an ssh
implementation on your platform (ssh or putty's plink).

--

Daniel Tryba

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
11190
by: Donnal Walter | last post by:
On Windows XP I am able to connect to a remote telnet server from the command prompt using: telnet nnn.nnn.nnn.nnn 23 where nnn.nnn.nnn.nnn is the IP address of the host. But using telnetlib, this code returns the traceback that follows: import telnetlib host = 'nnn.nnn.nnn.nnn'
0
1569
by: Fu Chen | last post by:
Hi pals! One of my client have a old UNIX application (but very important), it use telnet to operate. I am designing a web interface to this client. one of the work is building the UNIX application in a better interface. I try not to change any code in the old system for I don't want to take response for any trouble in their core system. Is there any trick to wrap the telnet in web environment? For example, i write a gateway in web...
5
33879
by: Greg Martz | last post by:
I'd like to do the following in C# and prefer using tcpclient rather than raw sockets... Connect to a unix box Login run date +%H%M%S retrieve the response. That's it, nothing more. This shouldn't be too complicated, I thought... I have yet to find any examples of being able to do this.
6
28462
by: MajorTom | last post by:
Hello, I getting this error An established connection was aborted by the software in your host machine here: TcpClient smtpSocket = new TcpClient(_serverSmtp, _portSmtp) port = 25 (smtp server) and my smtp server is working fine from the outlook program
2
4592
by: eight02645999 | last post by:
hi i am using a telnet session to simulate an authentication mechanism USER = "user" PASSWORD = "password" try: telnet = telnetlib.Telnet(HOST) telnet.set_debuglevel(5) telnet.read_until("login: ") telnet.write(USER + "\n") telnet.read_until("Password: ")
20
3956
by: valpa | last post by:
I'm a net admin for about 20 unix servers, and I need to frequently telnet on to them and configure them. It is a tiring job to open a xterm and telnet, username, password to each server. Can I do it automatically by python? After that, there have 20 xterm consoles opened and telneted to their corresponding servers. Then I could start to type command in these xterms. Any suggestion appreciate. Much thanks.
5
10084
by: anthony | last post by:
I am trying to find a simple example on how do telnet from VBA, but I am not having any luck. Most of the information I am finding is out dated or vauge at best. Here is what I need to do, 1. Build a text file from a table. 2. FTP this file to a UNIX server. 3. Execute a UNIX command to process the file. I have #1 and #2 working great, however I cant seem to find an easy
1
4276
by: getafixx | last post by:
Hello everyone, We have a linux server (Fedora core 7, default install, firewall turned off) and a bunch of windows XP machines on network/domain. All machines are visible and I can get to both windows and linux by various methods. We are trying to resolve a problem of not being able to connect to the linux box from the xp machines using python XMLRPC. (This is the module used in the software I am trying to set up) Python is at 2.4...
167
8335
by: darren | last post by:
Hi I have to write a multi-threaded program. I decided to take an OO approach to it. I had the idea to wrap up all of the thread functions in a mix-in class called Threadable. Then when an object should run in its own thread, it should implement this mix-in class. Does this sound like plausible design decision? I'm surprised that C++ doesn't have such functionality, say in its STL. This absence of a thread/object relationship in...
0
9353
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9975
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8794
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7342
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5241
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5384
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3889
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2765
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.