php telnet komut hiçbir yanıt

3 Cevap php

Windows XP Professional PHP5 koşuyorum. Ben sadece, bağlayan bir metin dizesi gönderir ve cevap tampon kapmak ve çıktılar bir telnet php komut dosyası yazmak çalışıyorum. Ben buradan telnet sınıf dosyasını kullanıyorum:

http://cvs.adfinis.ch/cvs.php/phpStreamcast/telnet.class.php

hangi i başka bir iş parçacığı bulundu.

<?php 
error_reporting(255);
ini_set('display_errors', true);

echo "1<br>";
require_once("telnet_class.php");

$telnet = new Telnet(); 

$telnet->set_host("10.10.5.7"); 
$telnet->set_port("2002");
$telnet->connect();
//$telnet->wait_prompt();
$telnet->write('SNRD   1%0d');
echo "3<br>";
$result = $telnet->get_buffer();
        echo $result;
        print_r($result);
//        flush_now();
echo "4<br>";

$telnet->disconnect();

?>

Ben hataları veya hiçbir yanıt alamıyorum. Ben geçersiz bir dize gönderirseniz, ancak ben bile alamadım en azından bir 'ERR' yanıtı almalısınız. I yanlış yapıyor olabilir Herhangi bir fikir ne? Ben komut isteminden aynı şeyi yaparsanız, ben ihtiyacım dize çıktısını alırsınız. Yazma fonksiyonu gönderiyor çünkü bu olabilir

3 Cevap

Kaynak kodu ve orijinal (Fransız) sitedeki bazı okuma başlığına atıfta sonra ....

<?php 
error_reporting(255);
ini_set('display_errors', true);

echo "1<br>";
require_once("telnet_class.php");

$telnet = new Telnet(); 

$telnet->set_host("10.10.5.7"); 
$telnet->set_port("2002");
if ($telnet->connect() != TELNET_OK) {
     printf("Telnet error on connect, %s\n",$telnet->get_last_error());
}
//$telnet->wait_prompt();
if ($telnet->write('SNRD   1' . "\xd") != TELNET_OK) {
     printf("Telnet error on write, %s\n",$telnet->get_last_error());
}

// read to \n or whatever terminates the string you need to read
if ($telnet->read_to("\n") != TELNET_OK) {  
     printf("Telnet error on read_to, %s\n",$telnet->get_last_error());
}
echo "3<br>";


$result = $telnet->get_buffer();
        echo $result;
        print_r($result);
//        flush_now();
echo "4<br>";

$telnet->disconnect();

?>

Tamam, açıklama: get_buffer () sadece, tampon içinde ne okuma. Tampon bir şey almak için $ maçına kadar tampon içine okuyacak read_to ($ maç) yürütmek zorunda. Bundan sonra, get_buffer size istenen string vermelidir.

EDIT: if you cannot find some string that follows the string you are interested in read_to will end in an error due to this part of the read_to method (translation of original french comment is mine):

    if ($c === false){
     // plus de caracteres a lire sur la socket
     // --> no more characters to read on the socket
        if ($this->contientErreur($buf)){
            return TELNET_ERROR;
        }

        $this->error = " Couldn't find the requested : '" . $chaine . "', it was not in the data returned from server : '" . $buf . "'" ;
        $this->logger($this->error);
        return TELNET_ERROR;
    }

Soket istenen dize bir maç olmadan kapatıldığında, TELNET_ERROR iade edilecektir anlamına gelir. Ancak, aradığınız dize bu noktada read_to iddiasına ne koydunuz .... tampon olmalıdır? Ben ne yaptım gibi ya da sadece "" "\ n"?

EDIT2 : there's also a problem with get_buffer. IMO this class is not really a timesaver ;-)

//------------------------------------------------------------------------
function get_buffer(){
    $buf = $this->buffer;

    // cut last line (is always prompt)
    $buf = explode("\n", $buf);
    unset($buf[count($buf)-1]);
    $buf = join("\n",$buf);
    return trim($buf);
}

It will throw away the last line of the response, in your case the one that contains the answer. I suggest to add a "light" version of get_buffer to the class, like this

//------------------------------------------------------------------------
function get_raw_buffer(){
    return $this->buffer;

}

ve gerekli sonucu kendinizi arama / düzeltme yok.

Ayrıca şu sürekli eklemek isteyebilirsiniz

define ("TELNET_EOF", 3);

ve bu gibi read_to değiştirmek

...
if ($c === false){
    // plus de caracteres a lire sur la socket
    if ($this->contientErreur($buf)){
        return TELNET_EOF;
    }

    $this->error = " Couldn't find the requested : '" . $chaine . "', it was not in the data returned from server : '" . $buf . "'" ;
    $this->logger($this->error);
    return TELNET_EOF;
}
...

Bu özel durum kendinizi tedavi etmek için (bir sonuç kodu TELNET_EOF sizin durumunuzda bir hata olarak tedavi edilmesi gerekmez). Sonunda kodunuzu bu gibi daha fazla veya daha az bakmak gerekir:

// read to \n or whatever terminates the string you need to read 
if ($telnet->read_to("\n") == TELNET_ERROR) {  
    printf("Telnet error on read_to, %s\n",$telnet->get_last_error()); }echo "3<br>";
}else {
    $result = $telnet->get_raw_buffer();
    echo $result;
    print_r($result);
}

Eğer telnet sınıf nasıl çalıştığını kontrol ettiniz mi? Belki windows altında çalıştırmak için tasarlanmamıştır. Eğer konuşma konum basit bir soket varsa, belki bunun yerine normal bir yuva bağlantısı kullanarak düşünün.

http://se2.php.net/sockets

Eğer yakın değil mi bir soket açarsanız, se sürece komut olarak netstat bir giriş çalışıyor olmalıdır.

netstat -na|find ":2002"

Böyle onaltılık değerler eklemek olamaz. Uzak süreç sadece görüyveya

SRND   1%0d

ve şimdi sona erdirilecek hattı için bekliyveya. Bu deneyin

$telnet->write('SNRD   1' . "\r");

veya

$telnet->write("SNRD   1\xd");

Bkz here çift tırnak, oldukça kritik

EDIT:

you might try adding some errveya repveyating as right now you don't really check much (errveya_repveyating won't show anything on the errveyas in the telnet class).... Fveya example:

<?php 
errveya_repveyating(255);
ini_set('display_errveyas', true);

echo "1<br>";
require_once("telnet_class.php");

$telnet = new Telnet(); 

$telnet->set_host("10.10.5.7"); 
$telnet->set_pveyat("2002");
if ($telnet->connect() != TELNET_OK) {
     printf("Telnet errveya on connect, %s\n",$telnet->get_last_errveya());
}
//$telnet->wait_prompt();
if ($telnet->write('SNRD   1' . "\xd") != TELNET_OK) {
     printf("Telnet errveya on write, %s\n",$telnet->get_last_errveya());
}

echo "3<br>";
$result = $telnet->get_buffer();
        echo $result;
        print_r($result);
//        flush_now();
echo "4<br>";

$telnet->disconnect();

?>

Ayrıca, sen \ r \ n hat sonlandırma ihtiyacı emin misin? yazma olarak tanımlanır

function write($buffer, $valeurLoggee = "", $ajouterfinLigne = true){

ve yapar

    if ($ajouterfinLigne){
        $buffer .= "\n";
    }

?

Also, did you test the host and pveyat with the command line telnet client? Like

telnet 10.10.5.7 2002

?