博联设备扫描脚本

博联Broadlink RM Pro/Mini、RM Home、MP1、MP2、SP mini等
版面规则
博联Broadlink RM Pro/Mini、RM Home、MP1、MP2、SP mini等
回复
头像
DT27
帖子: 345
注册时间: 周四 3月 30, 2017 08:54
Gender:

博联设备扫描脚本

帖子 DT27 »

本帖以树莓派为例,默认路径为~(即用户主目录/home/pi/)。

本脚本用于不方便在路由器中查看设备时,通过手动扫描获取博联设备ip及mac地址。

首先请查看Domoticz&BroadLink(博联)连接及控制教程:(一)安装python-broadlink

新建scanBroadlink.py

代码: 全选

sudo nano scanBroadlink.py
脚本内容

代码: 全选

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
#Script to locate Broadlink devices on local network by Graeme Brown Dec 23 2016
#请先使用博联APP配置添加设备。
 
import broadlink
import time
 
print "************************************************"
print "Using python library created by Matthew Garrett"
print "https://github.com/mjg59/python-broadlink"
print "************************************************"
print "扫描局域网中的Broadlink设备...."
 
mydevices = broadlink.discover(timeout=5)
print "找到" + str(len(mydevices )) + "个broadlink设备"
time.sleep(1)
print "..............."
 
for index, item in enumerate(mydevices):
 
  mydevices[index].auth()
 
  ipadd = mydevices[index].host
  ipadd = str(ipadd)
  print "设备 " + str(index + 1) +" IP地址 = " + ipadd[1:19]
  macadd = ''.join(format(x, '02x') for x in mydevices[index].mac[::-1])
  macadd = str(macadd)
 
  mymacadd = macadd[:2] + " " + macadd[2:4] + " " + macadd[4:6] + " " + macadd[6:8] + " " + macadd[8:10] + " " + macadd[10:12]
  print "设备 " + str(index + 1) +" MAC地址 = " + mymacadd
  print "..............."
保存并退出后直接执行

代码: 全选

sudo python ./scanBroadlink.py
回复