gpt4 book ai didi

修改cico dhcp池的php脚本

转载 作者:搜寻专家 更新时间:2023-10-31 22:07:26 29 4
gpt4 key购买 nike

我正在尝试自动化调制解调器配置系统的过程。下面的代码是我的尝试,但我没有列出传递变量的表单除外。

脚本的数据库部分运行良好。然而,telnet 部分并没有像我希望的那样进入路由器,任何人都可以对此有所了解。如果我打破 telnet 部分并通过 cli 运行它,它就可以工作。

<?

include("config.php");
//setting up db connection
try{
$dbh = new PDO("mysql:host=$host;dbname=$db", $mun, $mpass);
$dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );


$stmt = $dbh->prepare("INSERT INTO cust_info(firstname, lastname, staddr, city, phone, acct, ipaddr, hwaddr, cliid, bootfile)
VALUES (:firstname, :lastname, :staddr, :city, :phone, :acct, :ipaddr, :hwaddr, :cliid, :bootfile)");

$stmt->bindParam(':firstname', $_POST['firstname']);
$stmt->bindParam(':lastname', $_POST['lastname']);
$stmt->bindParam(':staddr', $_POST['staddr']);
$stmt->bindParam(':city', $_POST['city']);
$stmt->bindParam(':phone', $_POST['phone']);
$stmt->bindParam(':acct', $_POST['acct']);
$stmt->bindParam(':ipaddr', $_POST['ipaddr']);
$stmt->bindParam(':hwaddr', $_POST['hwaddr']);
$stmt->bindParam(':cliid', $_POST['cliid']);
$stmt->bindParam(':bootfile', $_POST['bootfile']);

$stmt->execute();
echo "done";
}
catch(PDOException $e)
{
echo 'failed: ' . $e->getMessage();
}


$bootfile = $_POST['bootfile'];
$cliid = $_POST['cliid'];
$ipaddr = $_POST['ipaddr'];
$hwaddr = $_POST['hwaddr'];

//Process data from form into cmts

$connection = fsockopen($router_ip, $port, $errno, $errstr, $timeout);

if(!$connection)
{
echo "Connection failed\n";
exit();
}
else
{
fputs($connection, "$username\r");
fputs($connection, "$password\r");
// using term length 0 to keep pause or more prompt from eating input
fputs($connection, "term length 0\r");
fputs($connection, "enable\r");
fputs($connection, "$password\r");
fputs($connection, "clear ip dhcp binding $ipaddr\r");
fputs($connection, "configure terminal\r");
fputs($connection, "ip dhcp pool $cliid\r");
fputs($connection, "host $ipaddr 255.255.255.0\r");
fputs($connection, "client-identifier $cliid\r");
fputs($connection, "bootfile $bootfile\r");
fputs($connection, "exit\r\n");
fputs($connection, "exit\r\n");
fputs($connection, "clear cable modem 172.16.16.248 reset\r\n");
fputs($connection, "show cable modem remote | inc $hwaddr\r");
fputs($connection, "exit\r");
}
{
fgets($connection, 128);
}
stream_set_timeout($connection, 2);
$timeoutCount = 0;
while (!feof($connection))
{
$content = fgets($connection, 128);
echo $content."<br>";

}
$info = stream_get_meta_data($connection);
if ($info['timed_out'])
{
// If timeout of connection info has got a value, the router not returning a output.
$timeoutCount++;
// We want to count, how many times repeating.
}
if ($timeoutCount >2)
{
// If repeating more than 2 times,
break;
// the connection terminating..
}

?>

最佳答案

Brad 给了我所需的提示,再次感谢

关于修改cico dhcp池的php脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16504382/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com