找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2452|回复: 4

[其它] 如何在3.2版本的API中使用find命令

[复制链接]
发表于 2009-5-29 14:52:19 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
操作如下:
用API客户端连接服务器后,输入
/ip/hotspot/user/find
则返回所有的用户ID。
我想实现如 find name=chen的功能,却实现不了,总告诉我语法错误。

另 虽然可以通过
/ip/hotspot/user/get
=.id=chen
的形式得到用户名为chen的资料,但此法会在系统中不存在chen用户的情况下报出异常ERROR: invalid item number,而不是find的空结果。

请高人指点,如何在API中使用find命令。
routeros
发表于 2009-5-29 17:51:17 | 显示全部楼层
3.21以后版本增加了查询命令


Queries print command accepts query words that limit set of returned items. This feature appeared in the 3.21 version.

Query words begin with '?'.
Order of query words is significant. Query is evaluated starting from the first word.
Query is evaluated for each item in the list. If query succeeds, item is processed, if query fails, item is ignored.
Query is evaluated using a stack of boolean values. Initially stack contains infinite amount of 'true' values. At the end of evaluation, if stack contains at least one 'false' value, query fails.
Query words operate according to the following rules:
?name  pushes 'true' if item has value of property name, 'false' if it does not.  
?-name  pushes 'true' if item does not have value of property name, 'false' otherwise.  
?name=x
?=name=x  pushes 'true' if property name has value equal to x, 'false' otherwise.  
?<name=x  pushes 'true' if property name has value less than x, 'false' otherwise.  
?>name=x  pushes 'true' if property name has value greater than x, 'false' otherwise.  
?#operations  applies operations to the values in the stack.
operation string is evaluated left to right.
sequence of decimal digits followed by any other character or end of word is interpreted as a stack index. top value has index 0.
index that is followed by a character pushes copy of value at that index.
index that is followed by the end of word replaces all values with the value at that index.
! character replaces top value with the opposite.
& pops two values and pushes result of logical 'and' operation.
| pops two values and pushes result of logical 'or' operation.
. after an index does nothing.
. after another character pushes copy of top value.


Examples:

Get all ethernet and VLAN interfaces:
/interface/print
?type=ether
?type=vlan
?#|
Get all routes that have non-empty comment:
/ip/route/print
?>comment=
routeros
回复

使用道具 举报

 楼主| 发表于 2009-5-30 21:42:21 | 显示全部楼层
很遗憾,我用的是3.20版的,能告诉我如果在API中使用FIND命令吗?
routeros
回复

使用道具 举报

 楼主| 发表于 2009-6-1 11:01:06 | 显示全部楼层
自己顶自己
routeros
回复

使用道具 举报

发表于 2009-6-1 11:28:31 | 显示全部楼层
在自己的程序中把异常ERROR处理掉就OK了
routeros
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|软路由 ( 渝ICP备15001194号-1|渝公网安备 50011602500124号 )

GMT+8, 2024-11-23 06:20 , Processed in 0.045780 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表