Small help @ php
#1

Hello all!
Well, during the last days i've been doing a small php socket connection for the remote server.(failled all times e.e)
And i am having a few problems with it.
I can connect into the ssh port, but i get "SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze1 Protocol mismatch."
And the code, which i've been doing is:
PHP код:
<?php
class servermanagement
{
    private 
$socket null;
    private 
$server null;
    private 
$port null;
    private 
$user null;
    private 
$pass null;
    private 
$exec "";
    public function 
__construct($server$port)
    {
        
$this->server $server;
        
$this->port $port;
        
$this->socket fsockopen("tcp://".$this->server$this->port$errno$errstr2);
        
socket_set_timeout($this->socket2);
                return;
    } 
    public function 
LoginOnTheServer($user$pass)
    {
        
$this->user $user;
        
$this->pass $pass;
        if(
$this->socket)
        {
            
fwrite($this->socket$this->user."\n"100);
            
sleep(5);
            
fwrite($this->socket$this->pass."\n"100);
        }
        return;
    }
    public function 
GetServerUptime()
    {
        if(
$this->socket)
        {
            
fwrite($this->socket"uptime\n"8);
        }
        
$data fread($this->socket4096);
        return 
$data;
    }
    public function 
CloseConnectionWithTheServer()
    {
        
fwrite($this->socket"exit\n"6);
        
fclose($this->socket);
        return;
    }
    
}
?>
I'm not experienced with class's, so sorry if it's badly coded...
Reply
#2

Sorry for bumping, done a small update @ code, it's already connecting into the ssh, but now i get the error:
php_network_getaddresses: getaddrinfo failed: Name or service not known

This is the hole class code:
PHP код:
<?php
class servermanagement
{
    private 
$socket null;
    private 
$server null;
    private 
$port null;
    private 
$user null;
    private 
$pass null;

    public function 
__construct($server$port$user$pass)
    {
        
$this->server $server;
        
$this->port $port;
        
$this->user $user;
        
$this->pass $pass;
        
$this->socket fsockopen("tcp://".$this->user.":".$this->pass."@".$this->server$this->port$errno$errstr10) or die($errstr);
        
socket_set_timeout($this->socket10);
        return 
1;
        
    } 
    public function 
GetServerUptime()
    {
        if(
$this->socket)
        {
            
fwrite($this->socket"uptime\n");
        }
        
$data fread($this->socket4096);
        return 
$data;
    }
    public function 
CloseConnectionWithTheServer()
    {
        
fwrite($this->socket"exit\n"6);
        
fclose($this->socket);
        return 
1;
    }
    
}
?>
Reply
#3

Try using socket_connect rather than fsockopen.
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Try using socket_connect rather than fsockopen.
Thanks for the tip, i'll try when my dedicated server thinks to came up online again, overheat security -.-

@ edited the hole code for sockets and not fsockopen, still the same problem -__-
But now it's just: SSH-2.0-OpenSSH_5.5p1 Debian-6+squeeze1

the hole code edited:
PHP код:
<?php
class servermanagement
{
    private 
$socket null;
    private 
$server null;
    private 
$port null;
    private 
$user null;
    private 
$pass null;
    public function 
__construct($server$port)
    {
        
$this->server $server;
        
$this->port $port;
        
$this->socket socket_create(AF_INETSOCK_STREAMSOL_TCP);
        
socket_connect($this->socket$this->server$this->port);
        
socket_set_timeout($this->socket10);
        
socket_listen($this->socket);
        return 
1;
        
    } 
    public function 
LoginIntoTheServer($user$pass)
    {
        
$this->user $user;
        
$this->pass $pass;
        
socket_listen($this->socket);
        
socket_write($this->socket$this->user);
        
sleep(5);
        
socket_write($this->socket$this->pass);
        return 
1;
    }
    public function 
GetServerUptime()
    {
        
socket_listen($this->socket);
        
socket_write($this->socket"uptime");
        
sleep(2);
        return 
socket_read($this->socket100);
    }
    public function 
CloseConnectionWithTheServer()
    {
        
socket_listen($this->socket);
        
socket_write($this->socket"exit"6);
        
socket_close($this->socket);
        return 
1;
    }
    
}
?>
Reply
#5

If you are trying to connect via SSH, you need to connect to it using the correct protocol. You can't just socket_connect().
Reply
#6

Quote:
Originally Posted by iLinx
Посмотреть сообщение
If you are trying to connect via SSH, you need to connect to it using the correct protocol. You can't just socket_connect().
That is the problem, if i Add there ssh, or telnet, both does not work, already searched, just show ssh2(which is the problem for some web hosting providers)
Reply
#7

Bump, well, i still did not fixed the problem, i just can connect into the remote server using ssh2 and expect, but i really want to connect via socket.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)