first try to use fing to look for MAC address on network
steps:
1. download fing from
http://www.overlooksoft.com/download site and install (with option key pressed to enable install)
2. then copy the attached code into applescript and compile and export to … /indigo 6/scripts/attachments
--- it needs your admin password as fing requires to be run with sudo. replace XXXXXXX in
set yourPassward to "XXXXXX" with your password.
!!!PLEASE BE AWARE THAT THIS IN CLEAR TEXT!!!!
although it likely will not leave your computer.
3. create scheduled action: "check myiphone" with embedded applescript eg:
set found to readfing("00:1E:E5:FA:4E:E4") -- this is the MAC address the programm will be looking for -- you have to know this. use fing to find it once: just type "fing" in terminal
if found = true then
do what ever you need to do
else
do what ever you need to do
end
4. you can check the data in /Users/yourid/Documents/fingdata and finglog
-- first time this script gets executed it waits (delay 10) for 10 secs to make sure that fing is running.
happy using
Karl
- Code: Select all
-- use fing to check if device with certain MAC address is on network
--
--
-- Karl Wachs
-- Sep 8 2013
-- V 0.53
-- added sudo requirement for fing, needs sudo password
-- no need for directory modification, use script to find current ID
--
-- using example script from outlooksoft web page
--
--
-- starts fing if not active
-- deletes data and log file before start
-- fing will stay active and will create log file and data file. log file will continuously increase. data file is analzed by this script
-- regular read seems to conflict with fing, use cat with pipe into applescript variable.
-- other info can be anayzed, ie date of last change, device up down,.. see code set theXXX to item x of at the end..
--
-- creates 2 files: ~/Documents/fingdata and finglog
--
--
(* example how to call:
set found to readfing("00:1E:E5:FA:xx:xx") -- this could be the MAC address of eg an iPhone
tell application "indigoServer"
set value of variable "iphoneInHouse" to found -- variable iphoneInHouse has to be created first
end
*)
on readfing(themacAddressToFind)
global theDir
global yourPassword
global theFile
global theLog
set userName to short user name of (system info)
set theDir to "/Users/" & userName & "/Documents/"
set theFile to "fingdata"
set theLog to "finglog"
set yourPassword to "XXXXXXXXXXXX"
-- init if needed
setupFing()
-- now check if macAddress is present
set found to findtheMacaddress(themacAddressToFind)
return found
end readfing
on setupFing()
global theDir
global theFile
global theLog
global yourPassword
--check if fing is already running, if not start it.
set pgmToFind to "fing.bin"
set theResponse to " "
try
set theResponse to do shell script "ps aux | grep '" & pgmToFind & "' | awk '{print $2}' "
end try
-- if pgmToFind is running then theResponse has 3 lines with 1 PID from : ps, xxxx itself and one more --- have not figured out which one..
set noOfWords to count words of theResponse
if noOfWords < 3 then -- if not running start script, remove old temp files and start fing
set cmd to "rm " & theDir & theFile & " &"
do shell script cmd
set cmd to "rm " & theDir & theLog & " &"
do shell script cmd
set cmd to "echo " & yourPassword & " | sudo -S fing -o table,csv," & theDir & theFile & " log,csv," & theDir & theLog & " >/dev/null 2>&1 &"
do shell script cmd
delay 10
end if
-- fing is running or has started
return
end setupFing
-------------------
on findtheMacaddress(themacAddressToFind)
set found to false
global theFile
global theDir
set noOfDevices to 0
--delay 10 --wait until fing has finished at least once
set cmd to "cat " & theDir & theFile
try
set FingContents to (do shell script cmd)
set noOfDevices to (count paragraphs of FingContents)
end try
if noOfDevices < 2 then -- read not successful .. must be more than 1 devices on network
return false
end if
set AppleScript's text item delimiters to {";"}
set nextDevice to 0
repeat while nextDevice < noOfDevices
set nextLine to paragraph (nextDevice + 1) of FingContents
set theItems to every text item of nextLine
set theIPNumber to item 1 of theItems as text
set theHostName to item 2 of theItems as text
set theStatus to item 3 of theItems as text
set theDate to item 4 of theItems as text
set theAssignedName to item 5 of theItems as text
set themacAddress to item 6 of theItems as text
set theVendor to item 7 of theItems as text
-- display dialog themacAddress
if themacAddress = themacAddressToFind then
if theStatus = "UP" then set found to true
set nextDevice to 9999 -- stop repeat
end if
set nextDevice to nextDevice + 1
end repeat
return found
end findtheMacaddress