dongzituo5530 2013-05-12 05:07
浏览 26
已采纳

用于修改cico dhcp池的php脚本

I'm trying to automate a process of a modem provisioning system. the code below is my attempt with the exception of a form that i did not list that is passing the variables.

the DB portion of the script is working well. however the telnet portion is not making it into the router as I had hoped can anyone shed some light on this. if I break the telnet portion out and run it via cli it works.

<?

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
";
exit();
}
else
{
fputs($connection, "$username");
fputs($connection, "$password");
// using term length 0 to keep  pause or more prompt from eating input
fputs($connection, "term length 0");
fputs($connection, "enable");
fputs($connection, "$password");
fputs($connection, "clear ip dhcp binding $ipaddr");
fputs($connection, "configure terminal");
fputs($connection, "ip dhcp pool $cliid");
fputs($connection, "host $ipaddr 255.255.255.0");
fputs($connection, "client-identifier $cliid");
fputs($connection, "bootfile $bootfile");
fputs($connection, "exit
");
fputs($connection, "exit
");
fputs($connection, "clear cable modem 172.16.16.248 reset
");
fputs($connection, "show cable modem remote | inc $hwaddr");
fputs($connection, "exit");
}
{
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..
 }

 ?> 
  • 写回答

1条回答 默认 最新

  • dongzhangji4824 2013-05-17 03:36
    关注

    Brad gave me the hints I needed to come to the required results thanks again

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算