you will need to install arp-scan from repositories
Code: Select all
sudo apt-get install arp-scan
Code: Select all
#!/usr/bin/python
import http.client
import requests
from subprocess import check_output
#################config ######################
mac = "Your Mac address"
idx = domoticz idx
###############################################
# ARP checking
#
out = check_output(["sudo","/usr/bin/arp-scan", "-l"]).decode('utf-8')
#
#look for mac
#
if mac in out:
#
#look for mac's ip
#
for elemento in out.split("\n"):
#mac ruben 'ac:c1:ee:2e:92:e6'
if mac in elemento:
linea = elemento.strip()
ip = linea[linea.find("192"):linea.find(" ")]
ping = check_output(["/bin/ping","-c 2" ,ip]).decode('utf-8')
#
#2 pings to the ip f
#
if '2 packets transmitted, 2 received' in ping:
#
# if the ip answers to ping turn the switch on
r = requests.get('http://192.168.1.101:8080/json.htm?type=command¶m=switchlight&idx=60&switchcmd=On&username=Y29tZWRvcg==&password=ZmFuaHVudGVy')
else:
#
# If not turn the switch off
#
r = requests.get('http://192.168.1.101:8080/json.htm?type=command¶m=switchlight&idx=60&switchcmd=Off&username=Y29tZWRvcg==&password=ZmFuaHVudGVy')
else:
#
#The mac isnt in the arp tables turn switch off
#
r = requests.get('http://192.168.1.101:8080/json.htm?type=command¶m=switchlight&idx=60&switchcmd=Off&username=Y29tZWRvcg==&password=ZmFuaHVudGVy')
print ('nadie en casa')
print (r.text)