doushe2513 2009-05-25 04:44
浏览 119

使用PHP进行telnet连接

I need to write a PHP script to telnet to a router, run a command and fetch the results. does anyone know a telnet connection library in PHP?

Update: This request (as is obvious) was for a long time ago. In the end I had to write the client library that I needed myself. The code for this library (and many more modules) is open source and available on github. Thanks everyone for your answers.

  • 写回答

4条回答 默认 最新

  • douwo1862 2009-06-23 22:27
    关注
    <?php
    
    $file = 'somefile.txt';
    $remote_file = 'readme.txt';
    // set up basic connection
    $ftp_server = '127.0.0.1';
    $ftp_user_name = 'Till';
    $ftp_user_pass = 'Kcp05';
    $conn_id = ftp_connect($ftp_server);
    // login with username and password
    ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
    // upload a file
    ftp_nb_put($conn_id, $remote_file, $file, FTP_ASCII);
    // close the connection
    echo "$file sent to $ftp_server as $remote_file
    <br/>";
    ftp_close($conn_id);
    
    
    // finished copying the input.dat to the till now, just need to execute the print command.
    // That will copy somefile.txt in the same folder as this .php file to the ftp server root dir.
    
    
    $header1=chr(0xFF).chr(0xFB).chr(0x1F).chr(0xFF).chr(0xFB).chr(0x20).chr(0xFF).chr(0xFB).chr(0x18).chr(0xFF).chr(0xFB).chr(0x27).chr(0xFF).chr(0xFD).chr(0x01).chr(0xFF).chr(0xFB).chr(0x03).chr(0xFF).chr(0xFD).chr(0x03).chr(0xFF).chr(0xFC).chr(0x23).chr(0xFF).chr(0xFC).chr(0x24).chr(0xFF).chr(0xFA).chr(0x1F).chr(0x00).chr(0x50).chr(0x00).chr(0x18).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x20).chr(0x00).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0x2C).chr(0x33).chr(0x38).chr(0x34).chr(0x30).chr(0x30).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x27).chr(0x00).chr(0xFF).chr(0xF0).chr(0xFF).chr(0xFA).chr(0x18).chr(0x00).chr(0x58).chr(0x54).chr(0x45).chr(0x52).chr(0x4D).chr(0xFF).chr(0xF0);
    
    $fp=pfsockopen("127.0.0.1",23);
    
    echo "Telnet session opening ...";
    
    sleep(4);
    
    fputs($fp,$header1); 
    sleep(4); 
    
    fputs($fp,"Till");
    sleep(2); 
    fputs($fp,"Kcp05"); 
    
    sleep(2);
    fputs($fp,"notepad"); 
    
    sleep(3);
    
    echo "Telnet session closing ...";
    
    fclose($fp);
    
    ?> 
    

    that worked for me. the first part will upload the ftp file to the server, and the second part will lo onto the telnet server, and execute a program that can use the file you just uploaded by ftp. tested it just now.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100