我需要使用php创建一个GUI来telnet路由器并执行traceroute命令到目标IP并在html页面上打印实时输出。
当前输出:
当前代码:
<html>
<head>
<title>Telnet-Router</title>
</head>
<body>
<?php
while (@ ob_end_flush());
$cmd='traceroute 8.8.8.8';
$telnet_con = fsockopen("172.16.1.2", 23, $errno, $errstr, 10);
if(!$telnet_con)
{
echo "Connection failed\n";
exit();
}
else
{
fwrite ($telnet_con, "myusername\r\n");
sleep(1);
fwrite ($telnet_con, "password\r\n");
sleep(1);
fwrite ($telnet_con, "$cmd\r\n");
fwrite ($telnet_con, "exit\r\n");
echo "Connected\n";
echo '<pre>';
while (!feof($telnet_con))
{
echo fread($telnet_con, 4096);
@ flush();
}
echo '</pre>';
fclose ($telnet_con);
}
?>
</body>
</html>