RouterOS Http API 定制服务端使用说明
- 定制开发
- 2023-06-08
- 2060热度
- 0评论
简介
该服务端为定制开发,主要用于Mikrotik RouterOS设备无线管理;
该服务端无前台界面,提供Http API对接使用;
设备RouterOS系统需要升级至V7.9.2最新稳定版本;
功能定制请联系微信:302268。
升级日志
2023-6-9 Ver 1.02:优化RouterOSv6.45-v6.49兼容性;
2023-6-8 Ver 1.01:优化自定义配置下的无线扫描处理方式,连接无线网络前保留网卡自定义参数;
RouterOS设备初始化脚本
{#2023-6-8 Ver1.02 适用于RouterOS API服务端对接设备初始化配置
#API端口
:local ApiPort "8728"
#API用户名
:local ApiUser "ApiUser"
#API用户密码
:local ApiPassword "password"
#-----------------------------
/ip service set api port=$ApiPort disabled=no
/user remove [find group=api]
/user group
remove [find name=api]
add name=api policy=api,write,read,test
/user
remove [find name=$ApiUser]
add name=$ApiUser password=$ApiPassword group=api
}
服务管理
查询服务状态
用途:获取API接口服务状态
方法:Get
路径:http://127.0.0.1:60006/status
参数:无
返回示例:
{
"code": 0,
"data": {},
"msg": "API服务启动时间:2023-06-08 01:44:11,在线时间:3分钟,系统版本:1.00"
}
关闭服务
用途:获取API接口服务状态
方法:Get
路径:http://127.0.0.1:60006/shutdown
参数:无
返回示例:
{
"code": 0,
"data": {},
"msg": "API服务将于3秒后关闭"
}
设备管理
添加新设备
用途:添加新设备,指定设备密钥
方法:Post
路径:http://127.0.0.1:60006/device/add
参数:
Key:设备密钥,建议不少于64位长度
Address:设备IP地址
Port:设备API端口号
User:设备API用户名
Password:设备API密码
返回示例:
{
"code": 0,
"data": {},
"msg": "新设备添加成功"
}
查询设备信息
用途:查询设备名称、型号、序列号、MAC地址、硬件版本号与软件版本号等信息
方法:Post
路径:http://127.0.0.1:60006/device/info
参数:
Key:设备密钥
返回示例:
{
"code": 0,
"data": {
"Name": "MikroTik",
"PackageVersion": "7.9.2 (stable)",
"FirmwareVersion": "7.9.2",
"BoardName": "hAP",
"Model": "RB951Ui-2nD",
"SN": "925108DB67C3",
"Interfaces": [
{
"Id": "*1",
"Name": "ether1",
"Mac": "CC:2D:E0:DA:A1:89"
},
{
"Id": "*2",
"Name": "ether2-1111",
"Mac": "CC:2D:E0:DA:A1:8A"
},
{
"Id": "*3",
"Name": "ether3",
"Mac": "CC:2D:E0:DA:A1:8B"
},
{
"Id": "*4",
"Name": "ether4",
"Mac": "CC:2D:E0:DA:A1:8C"
},
{
"Id": "*5",
"Name": "ether5",
"Mac": "CC:2D:E0:DA:A1:8D"
},
{
"Id": "*6",
"Name": "wlan1",
"Mac": "CC:2D:11:11:11:11"
}
]
},
"msg": "操作成功"
}
无线管理
查询设备无线网卡信息及状态
用途:查询设备无线网卡全部信息,以及信号收发强度、信号质量CCQ、无线频段、无线速率等属性
方法:Post
路径:http://127.0.0.1:60006/wifi/info
参数:
Key:设备密钥
返回示例:
{
"code": 0,
"data": [
{
".id": "*6",
"adaptive-noise-immunity": "none",
"allow-sharedkey": "false",
"ampdu-priorities": "0",
"amsdu-limit": "8192",
"amsdu-threshold": "8192",
"antenna-gain": "2",
"area": "",
"arp": "enabled",
"arp-timeout": "auto",
"band": "2ghz-b/g",
"basic-rates-a/g": "6Mbps",
"basic-rates-b": "1Mbps",
"bridge-mode": "enabled",
"channel-width": "20mhz",
"compression": "false",
"country": "etsi",
"default-ap-tx-limit": "0",
"default-authentication": "true",
"default-client-tx-limit": "0",
"default-forwarding": "true",
"default-name": "wlan1",
"disable-running-check": "false",
"disabled": "false",
"disconnect-timeout": "3s",
"distance": "dynamic",
"frame-lifetime": "0",
"frequency": "auto",
"frequency-mode": "regulatory-domain",
"frequency-offset": "0",
"guard-interval": "any",
"hide-ssid": "false",
"ht-basic-mcs": "mcs-0,mcs-1,mcs-2,mcs-3,mcs-4,mcs-5,mcs-6,mcs-7",
"ht-supported-mcs": "mcs-0,mcs-1,mcs-2,mcs-3,mcs-4,mcs-5,mcs-6,mcs-7,mcs-8,mcs-9,mcs-10,mcs-11,mcs-12,mcs-13,mcs-14,mcs-15,mcs-16,mcs-17,mcs-18,mcs-19,mcs-20,mcs-21,mcs-22,mcs-23",
"hw-fragmentation-threshold": "disabled",
"hw-protection-mode": "none",
"hw-protection-threshold": "0",
"hw-retries": "7",
"installation": "any",
"interface-type": "Atheros AR9300",
"interworking-profile": "disabled",
"keepalive-frames": "enabled",
"l2mtu": "1600",
"mac-address": "CC:2D:11:11:11:11",
"max-station-count": "2007",
"mode": "station",
"mtu": "1500",
"multicast-buffering": "enabled",
"multicast-helper": "default",
"name": "wlan1",
"noise-floor-threshold": "default",
"nv2-cell-radius": "30",
"nv2-downlink-ratio": "50",
"nv2-mode": "dynamic-downlink",
"nv2-noise-floor-offset": "default",
"nv2-preshared-key": "",
"nv2-qos": "default",
"nv2-queue-count": "2",
"nv2-security": "disabled",
"nv2-sync-secret": "",
"on-fail-retry-time": "100ms",
"preamble-mode": "both",
"radio-name": "CC2DE11111111",
"rate-selection": "advanced",
"rate-set": "default",
"running": "true",
"rx-chains": "0,1",
"scan-list": "default",
"secondary-frequency": "",
"security-profile": "default",
"skip-dfs-channels": "disabled",
"ssid": "",
"station-bridge-clone-mac": "00:00:00:00:00:00",
"station-roaming": "disabled",
"supported-rates-a/g": "6Mbps,9Mbps,12Mbps,18Mbps,24Mbps,36Mbps,48Mbps,54Mbps",
"supported-rates-b": "1Mbps,2Mbps,5.5Mbps,11Mbps",
"tdma-period-size": "2",
"tx-chains": "0,1",
"tx-power-mode": "default",
"update-stats-interval": "disabled",
"vlan-id": "1",
"vlan-mode": "no-tag",
"wds-cost-range": "50-150",
"wds-default-bridge": "none",
"wds-default-cost": "100",
"wds-ignore-ssid": "false",
"wds-mode": "disabled",
"wireless-protocol": "any",
"wmm-support": "disabled",
"wps-mode": "push-button",
"Wifi": {
"status": "connected-to-ess",
"authenticated-clients": "1",
"authentication-type": "wpa2-psk",
"bridge": "false",
"bssid": "4C:5E:11:11:11:11",
"channel": "2447/20/g(18dBm)",
"compression": "false",
"current-distance": "1",
"current-tx-powers": "1Mbps:15(1518,2Mbps:15(1518,5.5Mbps:15(1518,11Mbps:15(1518,6Mbps:15(1518,9Mbps:15(1518,12Mbps:15(1518,18Mbps:15(1518,24Mbps:15(1518,36Mbps:15(1518,48Mbps:15(1518,54Mbps:15(1518",
"encryption": "aes-ccm",
"framing-mode": "none",
"group-encryption": "aes-ccm",
"last-ip": "192.168.88.68",
"management-protection": "false",
"noise-floor": "-107",
"notify-external-fdb": "false",
"nstreme": "false",
"overall-tx-ccq": "10",
"p-throughput": "29975",
"radio-name": "4C5E011111111",
"routeros-version": "7.9.2",
"rx-ccq": "10",
"rx-rate": "1Mbps",
"signal-strength": "-19",
"signal-strength-ch0": "-23",
"signal-strength-ch1": "-21",
"signal-strength-ch2": "",
"signal-strength-ch3": "",
"signal-to-noise": "88",
"ssid": "WifiTest",
"tx-ccq": "10",
"tx-rate": "54Mbps",
"tx-signal-strength": "-26",
"tx-signal-strength-ch0": "-29",
"tx-signal-strength-ch1": "-29",
"tx-signal-strength-ch2": "",
"tx-signal-strength-ch3": "",
"wds-link": "false",
"wireless-protocol": "802.11",
"wmm-enabled": ""
}
}
],
"msg": "操作成功"
}
扫描设备附近的无线网络
用途:扫描设备附近的无线网络,返回网络信息数组;该接口根据设备当前联网状态,自动切换前后台扫描,不影响已连接Wifi网络数据传输
方法:Post
路径:http://127.0.0.1:60006/wifi/scan
参数:
Key:设备密钥
WifiId:网卡ID,示例:*6
返回示例:
{
"code": 0,
"data": [
{
".section": "1",
"address": "78:91:33:88:11:E6",
"channel": "2412/20/gn(18dBm)",
"sig": "-61",
"ssid": "ChinaNet-UCWSD"
},
{
".section": "1",
"address": "18:AA:26:BF:11:F6",
"channel": "2417/20/gn(18dBm)",
"sig": "-85",
"ssid": "ChinaNet-wAYHX"
},
{
".section": "2",
"address": "78:91:E9:81:11:E6",
"channel": "2412/20/gn(18dBm)",
"sig": "-61",
"ssid": "ChinaNet-UCSAD"
},
],
"msg": "操作成功"
}
连接至指定无线网络
用途:根据提供的SSID、MAC地址信息,连接至指定的无线网络,信号强度正常的情况下,3秒内可建立连接;连接成功后,无线网卡状态Status变为:connected-to-ess,同时AuthenticatedClients数值大于0
方法:Post
路径:http://127.0.0.1:60006/wifi/conn
参数:
Key:设备密钥
WifiId:网卡ID,示例:*6
Ssid:无线SSID名称
Mac:无线网络MAC地址,用于区分同名SSID的不同AP设备
Password:无线网络密码
返回示例:
{
"code": 0,
"data": {},
"msg": "已执行Wifi连接,请稍候查看无线网卡状态"
}