douyi6960 2017-04-05 20:44
浏览 106
已采纳

Mikrotik:使用PHP API更改usermanager用户密码

I'm trying to create a PHP code that can change a user password using PHP API, here is my code so far:

<?php

require('routeros_api.class.php');

$API = new routerosAPI();

$API->debug = true;

if ($API->connect('192.168.0.101', 'user', 'password')) {

  $API->write('/tool/user-manager/user/getall', false);
    $API->write('=.proplist=username', false);
    $API->write('?username=john');
    $API->write('/tool/user-manager/user/set',false);
    $API->write('password=4321');    

  $READ = $API->read(false);
  $ARRAY = $API->parseResponse($READ);
  print_r($ARRAY);
   $API->disconnect();
}
?>

When I run this code it appears to only return the username I'm searching but the password doesn't change. Any help?

  • 写回答

1条回答 默认 最新

  • duankuang7928 2017-04-06 17:03
    关注

    You are using incorrect commands. I was not using PHP API, so some parts will be described by words instead of code.

    First of all you need to get ID of the record to edit. If username is john, it will be:

    $API->write('/tool/user-manager/user/print', false);
    $API->write('=.proplist=.id', false);
    $API->write('?username=john');
    

    Read and parse response. For example returned .id is *1. Use this to change password:

    $API->write('/tool/user-manager/user/set', false);
    $API->write('=.id=*1', false);
    $API->write('=password=new_pass');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝