Sep-06-2022, 04:32 PM
Hello everybody,
I'm trying to write a script that first checks some ips of mine (phone, pc, etc.) which are stored in a json file to "confirm" that I'm home. If one ip is online (indicating that I'm home) it should do something (#DoSomething1). If no ip is online it should check for my iphone location (#CheckiPhoneLocation) and this is the point where i struggle. Does someone know a way to check an iPhone location? Maybe there is an FindMyiPhone-API or one by a third party?
I'm trying to write a script that first checks some ips of mine (phone, pc, etc.) which are stored in a json file to "confirm" that I'm home. If one ip is online (indicating that I'm home) it should do something (#DoSomething1). If no ip is online it should check for my iphone location (#CheckiPhoneLocation) and this is the point where i struggle. Does someone know a way to check an iPhone location? Maybe there is an FindMyiPhone-API or one by a third party?
#!/usr/bin/env python3
#Imports
from subprocess import call, DEVNULL
import platform
import json
import sys
#Host Configuration
with open("/home/pi/system/index/alphaClients.json") as f1:
data1 = json.load(f1)
with open("/home/pi/system/index/externClients.json") as f2:
data2 = json.load(f2)
#IP Configuration
responding_alphaHosts = 0
responding_externalHosts = 0
#Pinp Configuration
def ping(host_or_ip: str) -> bool :
if platform.system().lower() == "windows":
countoption = "/n"
else:
countoption = "-c"
return not call(["ping", countoption, "1", host_or_ip],
stdout=DEVNULL, stderr=DEVNULL)
#Host Check
for i in data1:
if ping(i["ip"]):
responding_alphaHosts += 1
for i in data2:
if ping(i["ip"]):
responding_externalHosts += 1
#ToDo
if responding_alphaHosts > 0 :
if responding_externalHosts == 0:
#DoSomething1
else:
#CheckForiPhoneLocation
if iPhoneLocation is xyz:
#DoSomething1
else:
#DoSomething2
#End
sys.exit()
