Using Fing as a new way to detect smartphone presence

Posted on
Thu Sep 12, 2013 10:34 am
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

l[/quote]
I will check. I do see that if Fing is started with no parameters, it will launch all FingSentinel files found in /usr/lib/fing/launchd

The one file, com.overlooksoft.FingSentinel.plist is as follows:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>com.overlooksoft.FingSentinel</string>
        <key>RunAtLoad</key>
        <true/>
        <key>Disabled</key>
        <false/>
        <key>GroupName</key>
        <string>wheel</string>
        <key>UserName</key>
        <string>root</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/bin/fing</string>
                <string>--sentinel</string>
        </array>
        <key>KeepAlive</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/var/log/fing/stderr.log</string>
        <key>StandardOutPath</key>
        <string>/var/log/fing/stdout.log</string>
</dict>
</plist>


Right now, I have two instances of fing.bin running and FingBox and FingScan both appear to be working correctly.[/quote]


this will work if you start fingscan first and then fing sentinel -- if an instance of fing is already running fingscan will not start another one and it will not create the required files

..

could you try to add a section that would create fingdata and finglog in ~/documents/fing

and could you check which files are in these directories and what format is the data. (attach some lines from the files to a response)

Karl

Posted on
Thu Sep 12, 2013 11:05 am
Dewster35 offline
Posts: 1030
Joined: Jul 06, 2010
Location: Petoskey, MI

Re: Using Fing as a new way to detect smartphone presence

kw123 wrote:
Dewster35 wrote:
Finally getting around to trying this out and I'm getting the following error message in the event log.


Schedule Check Dave iPhone
Error script error: «script» doesn’t understand the readfing message. (-1708)

I have the scheduled action running every 10 seconds for now for testing purposes. All I am doing with that action is changing a variable from home to away.



I have stopped the readfing path. the "NEW" and "IMPROVED" one is fingscan.

difference: fingscan runs continuously, creates a whole list of all ipdevices on your network with info on last change, # of changes etc.
trigger on change on any change of variable ipDdevicenn and check for contains "up" or "down" to drive action.

Karl


Curious if you could create another post with instructions for setting up and using this based on the latest build? So it's a simple copy and paste for the less savvy among us?

Posted on
Thu Sep 12, 2013 11:59 am
Bollar offline
Posts: 528
Joined: Aug 11, 2013

Re: Using Fing as a new way to detect smartphone presence

kw123 wrote:
this will work if you start fingscan first and then fing sentinel -- if an instance of fing is already running fingscan will not start another one and it will not create the required files

..

could you try to add a section that would create fingdata and finglog in ~/documents/fing

and could you check which files are in these directories and what format is the data. (attach some lines from the files to a response)

Karl

I couldn't change the directory, but I did enable logging. Logs are stored in /var/log/fing/ Here's a sample named fing-20130912.125137.log:

Code: Select all
INFO  2013/09/12 12:51:37.990 === overlook fing 2.2 - www.overlooksoft.com ===
INFO  2013/09/12 12:51:37.990 Host platform: Mac (64 bit)
INFO  2013/09/12 12:51:37.991 Command Line: /usr/lib/fing/fing.bin --sentinel
INFO  2013/09/12 12:51:37.994 Fingbox discovery service starting for config: /var/data/fing/sentinel/My_Account-Guest.fingbox
INFO  2013/09/12 12:51:37.995 Fingbox netdiscovery starting on: 172.16.42.0/24 (Ethernet)
INFO  2013/09/12 12:51:37.995 Fingbox NUI: eth-28CFDA057B63-172.16.42.0-24
INFO  2013/09/12 12:51:37.995 Fingbox refresh interval: 600
INFO  2013/09/12 12:51:37.995 Fingbox discovery service starting for config: /var/data/fing/sentinel/My_Account.fingbox
INFO  2013/09/12 12:51:37.996 Fingbox netdiscovery starting on: 10.0.0.0/24 (Ethernet)
INFO  2013/09/12 12:51:37.996 Fingbox NUI: eth-C82A145503CB-10.0.0.0-24
INFO  2013/09/12 12:51:37.996 Fingbox refresh interval: 600
INFO  2013/09/12 12:51:37.996 Fingbox data folder: /var/data/fing/box/My_Account-Guest.fingbox
INFO  2013/09/12 12:51:37.996 Fingbox data folder: /var/data/fing/box/My_Account.fingbox
INFO  2013/09/12 12:51:37.996 Refreshing user profile for account rick@My_Account.com / eth-C82A145503CB-10.0.0.0-24
INFO  2013/09/12 12:51:37.996 Refreshing user profile for account rick@My_Account.com / eth-28CFDA057B63-172.16.42.0-24
INFO  2013/09/12 12:51:39.316 Network discovery started on 10.0.0.0/24 (data-link layer)
INFO  2013/09/12 12:51:39.317 Discovery round started on 10.0.0.0/24
INFO  2013/09/12 12:51:39.318 Network discovery started on 172.16.42.0/24 (data-link layer)
INFO  2013/09/12 12:51:39.318 Discovery round started on 172.16.42.0/24
INFO  2013/09/12 12:51:43.846 Discovery round completed on 10.0.0.0/24
INFO  2013/09/12 12:51:44.127 Discovery round completed on 172.16.42.0/24
INFO  2013/09/12 12:51:44.848 Network discovery completed on 10.0.0.0/24
INFO  2013/09/12 12:51:44.850 Network snapshot sync </var/data/fing/box/My_Account.fingbox/141134CC133.fingnet>
INFO  2013/09/12 12:51:45.129 Network discovery completed on 172.16.42.0/24
INFO  2013/09/12 12:51:45.130 Network snapshot sync </var/data/fing/box/My_Account-Guest.fingbox/141134CC136.fingnet>
INFO  2013/09/12 12:51:45.487 Network snapshot sync <eth-C82A145503CB-10.0.0.0-24> success (122)
INFO  2013/09/12 12:51:45.937 Network snapshot sync <eth-28CFDA057B63-172.16.42.0-24> success (123)

Insteon / Z-Wave / Bryant Evolution Connex /Tesla / Roomba / Elk M1 / SiteSage / Enphase Enlighten / NOAA Alerts

Posted on
Thu Sep 12, 2013 5:14 pm
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

UPDATE!! ==> fingscan & fingscaninstall.app now posted on www.copy.com in shared folder

the apps are shared on this drive
https://copy.com/ak4zXRrPUccVmR4h

code should be ready for general use.

Karl .. ready to go for a swim..


a) copy code and compile locally:
0. install fing from overlooksoft.com

copy applescript code:
1. select file1(fingscaninstall) copy code open applescript and paste code
-save as fingscaninstall on desktop
- export as app on desktop

2, select 2. file(fingscan) copy code open applescript and paste code
-save as fingscan on desktop (must be the same as above)
- export as app on desktop with option stay running after run handler
3. doubleclick on fingscaninstall.app


b) with download from shared drive,
steps to install

0 install fing from overlooksoft.com
1. download the posted 2 files
2. double click on fingscaninstall in downloads
3. click ok ...

=======


result:
- fingscan.app will be copied into ../Indigo 6 or 5 or 4/scripts/attachments/fingscan.app
- it will be launched, you have to enter your password to enable fing.bin to run
- a scheduled action is created : fingscanrelaunch it will run once a day to launch fingscan if not running.
- fingscan will after 10 seconds scan your network and present to you enter nicknames for each device
it will create variables ipDevicesnn with information for each device e.g.:
HP-Printer;2C:76:8A:BF:51:A1;192.168.1.164;HP;up;2013/09/12 02:43:12;2
nickname;mac#;ip#;vendor;timestamp-of-lastchange;#of-up/down

in addition a a timestamp variable ipDevsLastupdate gives the time of last change in network
and ipDevsAlive flips between 1 and -1 every time is checks the network

new devices or devices coming back from sleep will be detected in ~ 5 secs,
if a devices go to sleep it will take ~ 1 minute to update indigo.

you can edit the variables values (ie change the nickname) but MUST NOT change ";mac#;" the 2C:76...

your can setup a trigger to use the info of eg ipDevice15:

if variable ipDevice15 has any change, and variable contains ";down" then do your action eg say " ip device 22 is down"


and attached the files:

1. fingscaninstall
Code: Select all
-- fingscaninstall into indigo folder  (copied and adapted from Nathan Sheldon etrack.app)
-- Karl Wachs
-- v0.2
-- v0.2 formatting changes
--
-- Sept 12 2013
-- required:
-- download fingscanapp and installfingscan.app into ~/Downloads/:  just download the files in safari. they should end up there, then doubleclick on fingscaninstall
-- what it does:
-- checks directories which indigo version is installed
--    copies into latest version
--   starts fingscan
-- creates a scheduled action   "fingscanreload"  to start fingscan,(fingscan checks if already running and quits if second instance)
--

set lf to ASCII character 10
set theApp to "fingscan.app"
set install to true
set userName to short user name of (system info)

-- Verify  that the "theAPP"  Indigo Attachment file exists in the same folder as this program.

set myPath to (path to me) as text
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set chunks to text items of myPath
if last item of chunks is "" then set chunks to chopLast(chunks)
-- the above accounts for script applications that are package folders
set myFolderPath to chopLast(chunks) as text
set myFolder to POSIX path of myFolderPath & "/" -- this is where this application is located,  fingscan.app must be in teh same folder
set AppleScript's text item delimiters to tid

set theAPPfile to myFolder & theApp -- and the full path with app

set msg to "no"
tell application "Finder" to if exists theAPPfile as POSIX file then set msg to "yes"

if msg = "no" then
   tell me
      display dialog "FINGSCAN INSTALL" & lf & "The " & theApp & " Indigo attachment file could not be found in the same folder as this setup program.  In order to install " & theApp & " into your Indigo system, the " & theApp & " file that was included with this setup program must be in the same folder as this program." buttons {"OK"} default button 1
      return false
   end tell
end if

-- all surces in right place


-- find indigo folder
set theIndigoFolder to ""
tell application "Finder"
   -- find newest of the supported Indigo version.
   set ii to 20 -- start with indigo version 20…   yes, we are optimistic!!
   repeat while ii > 1
      set theFolder to "/Library/Application Support/Perceptive Automation/Indigo " & ii & "/IndigoServer.app"
      if exists theFolder as POSIX file then
         set theIndigoFolder to "/Library/Application Support/Perceptive Automation/Indigo " & ii & "/"
         set ii to 0
      end if
      set ii to ii - 1
   end repeat
end tell

set destinationFolder to theIndigoFolder & "Scripts/Attachments/"


tell application "Finder"
   set destinationFile to destinationFolder & "fingscan.app"
   set install to true
   try -- See if the file already exists in the installation location.
      set destinationFinderFile to (POSIX file destinationFile) as Unicode text
      tell me
         set overwriteOrSkip to button returned of (display dialog "FINGSCAN INSTALL" & lf & destinationFolder & " is already installed. Click \"Overwrite\" to re-install the attachment or \"Skip\" to skip the installation of the " & theApp & "  attachment." buttons {"Overwrite", "Skip"} default button 2)
      end tell
      if overwriteOrSkip is "Skip" then
         set install to false
      end if
   on error -- Meaning the file does NOT already exist in the installation location.
      set install to true
   end try
   
   
   -- Install the theAPP Indigo Attachment if we'resupposed to.
   if install is true then
      tell me
         set installChoice to button returned of (display dialog " FINGSCAN INSTALL" & lf & "   We're now ready to install. " buttons {"Cancel", "OK"} default button 2)
      end tell
      if installChoice is "OK" then
         do shell script "cp -R " & quoted form of theAPPfile & " " & quoted form of destinationFolder & " & " -- copy to indigo folder
         
         
         try -- just in case its already there
            tell application "IndigoServer"
               make new time date action with properties {name:"fingscanrelaunch", days of week:"1111111"}
            end tell
         end try
         try -- just in case its already there
            tell application "IndigoServer"
               set action type of action step 1 of time date action "fingscanrelaunch" to executeScript
               set script code of action step 1 of time date action "fingscanrelaunch" to cmd
            end tell
         end try
         tell me
            activate
            display dialog "FINGSCAN INSTALL" & lf & " is installed, ready to be launched, " & lf & " and scheduled action    fingscanrelauch   will run once a day to (re)start fingscan " buttons {"OK"} giving up after 60
         end tell
         
         do shell script "open '" & destinationFolder & theApp & "'  &" -- and start it
         set cmd to "do shell script  \"open '" & destinationFolder & theApp & "'  &  \" "
         
         
      else
         tell me
            activate
            display dialog "FINGSCAN INSTALL" & lf & "has been canceled." buttons {"OK"} default button 1 giving up after 60
            return false
         end tell
      end if
   end if
end tell


return true

end

on chopLast(theList)
   return reverse of (rest of (reverse of theList))
end chopLast




2. fingscan
Code: Select all
-- fingscan.app
-- build list of network devices using FING
-- runs in background, iddles for 5 secs then checks if FING has found new configs
-- creates variables with ipdevice info
--
--
-- Karl Wachs
-- Sep 12 2013
-- please use as you see fit
-- V 1.0
-- 0.81 one code fix, if IP number change: wrong quotes for variable
-- 0.82 added comments, clearer code,  and reset logfile once a day
-- 0.9  added check logfile for any change, if no chang skip checks, faster reaction, and less code excution,  most of the time nothing changes. this will only check size of  file "finglog" 
-- 0.95 check for change in fingdata file. if time stamp changed get all data and update indigo (1/minute)
--  adding a device results in an update of indigo within 6 secs, detection of disconnecting a debvice takes up to 65 secs.  connecting sends traffic, disconnecting in most cases no, have to wait until next ping cycle (1/minute)
-- 0.97 add 4 password options (set passWordOption to 0 or 1 or 2 or 3  see code for details
-- 0.971 OOI variable fix,
-- 0.973 set lastLogFilesize to logFilesize was at the wrong place,
-- bad logic with logMACaddress fixed  (was old code from old logic)
-- add heartbeat (-1 / 1)  display in indigo everytime it runs
-- change ipDevsLastUpdate to last time variables were fully checked or any new device added etc
-- 0.98  added counter of number of up/down of each device
-- 0.99 added "activate" before display dialog, to make sure pop windows for new devices goes into foreground
--       fixed situation when indigoNoOfChanges is not a number, set to 0 (try .. on error  set … to 0)
-- 1.0 added & clarified comments and fixed spelling
--    check if fingscan is already running  ==> quit
--
-- how to install:
--  copy this script into applescript editor, save into .../indigo 6/scripts/attachments
-- export into …/indigo 6/scripts/attachments  as APP with "stay open after run handler.."
-- then start fingscan using finder (doubleclick on fingscan.app in /indigo 6/scripts/attachments)
--
--  use in indigo as trigger:
--  setup trigger "IPdevice22 down"
--      trigger if any change to ipDevice22
--      condition ipDevice22 must contain ";down"   "down" (without ";" ) probably also works, but you might have a device's name up or down or vendor's name may contain string up or down
--       action: whatever you like
--
-- what it does:
-- starts fing if not active
-- creates fing directory in  ~/Documents/  for data
-- will ask for approval to use keychain for sudofing command / userid .. see password options
-- will run every 5 seconds and check finglog file size, if changed check fingdata file for new info
-- will create/ update varibales ipDevicenn  nn = 01 .. 99
-- will update ipDevsLastUpdate with last date/time of last change
-- will update ipDevsAlive  toggle 1/-1 everytime it run as heat beat
-- will ask for each new MAC address to assign nickname
-- ipDevicenn will contain  nickname;macaddress;ip#;vendor;up/downinfo;date of last change if any;#of"up/downs"
--                           eg:iPHONE4-dad;14:8F:C6:74:87:58;192.168.1.148;Apple;up;2013/09/12 00:28:11;2
-- fing will stay active and will create log file and data file.  log file will continuously increase (fing will reset at ~ 350kb).  finglog file is checked for changed file size, fingdata file is analzed by this script once it changes
-- regular read seems to conflict with fing, we use cat with pipe into applescript variable.
--
-- needs to be fixed:
-- does not allow non consequtive ipDevice03 ..05     eg 04 missing by eg deleting a  variable
-- tried to put fing output files into indigo directory, but fing does not like spaces in directories, so i put the outputfiles into User/yourid/Documents/fing/ fingdata and finglog
--
--
-- added 4 password options
-- 0.  set password in code
-- 1. ask for password in dialog box
-- 2. use keychain to get password
-- 3. sudo without password works only o=if fing has been enabled to run without password, see option 3 in code what to do.
--  uses ~ 0.1-2% of one cpu  (mostly 0.1%)


on quit -- enable quit
   continue quit
end quit

on run -- this is done only once at time of "open"
   global debug
   global theDir
   global userName
   global theFile
   global theLog
   global lastLogFilesize
   global logFilesize
   global noOfDevices
   global FingContents
   global noOfIndigoDevices
   global IndigoIpDevices
   global lastUpdate
   global passwordOption
   global yourPassword
   global alive
   set yourPassword to "" -- use this if paaswordOption = 0
   set passwordOption to 3 --  0= set password in code,  1= use keychain to get password, 2 = enabel fing to not require password, 3 = enter password when running
   set userName to short user name of (system info)
   set theDir to "/Users/" & userName & "/Documents/fing/"
   set theFile to "fingdata"
   set theLog to "finglog"
   set lastLogFilesize to 0
   set logFilesize to 0
   set newDevice to 0
   set lastUpdate to ""
   set alive to 1
   
   
   
   --  quit if already running
   try
      set theResponse to do shell script "ps aux | grep 'fingscan' | awk '{print $2}' "
   end try
   -- if pgmToFind is running then theResponse has 3 lines with PIDs from :     ps, fingscan itself and one more --- have not figured out which one..
   set ii to count words of theResponse
   if ii > 3 then quit -- run just one instance
   -- end quit if already running
   
   
   
   -- init if needed
   setupFing()
   
   -- send to idle
   idle
   
   -- finish main pgm from now on on idle takes over
end run


on idle -- every 5 seconds this gets executed
   
   global theDir
   global userName
   global theFile
   global theLog
   global lastLogFilesize
   global logFilesize
   global newDevice
   global noOfDevices
   global FingContents
   global noOfIndigoDevices
   global IndigoIpDevices
   global lastUpdate
   global anyChange
   global alive
   
   set anyChange to 0
   
   
   set noOfLines to 0
   set AppleScript's text item delimiters to {";"}
   
   -- update indigo with time stamp
   set theTime to text -8 thru -1 of ((current date) as «class isot» as string)
   
   
   -- check file size of logfile, if its larger than last time, new data
   set cmd to "ls -l " & theDir & theLog & "| awk '{print $5}'"
   set logFilesize to do shell script cmd
   if logFilesize > lastLogFilesize then -- there must be a new entry in finglog
      set lastLogFilesize to logFilesize
      -- read latest fingdata log file (just last line)
      getFingIPlogdata()
      
      if noOfDevices > 0 then -- read not successful .. must be more than 0 devices changed on network
         -- yes there is really new data to use:
         -- use last line of FINGlog for new information
         set nextLine to paragraph 1 of FingContents
         set theItems to every text item of nextLine
         set theLOGIPNumber to item 3 of theItems as text
         set theLOGStatus to item 2 of theItems as text
         set theLOGDate to item 1 of theItems as text
         set theLOGmacAddress to item 6 of theItems as text
         set theLOGVendor to item 7 of theItems as text
         
         -- get all devices stored in indigo  into IndigoIpDevices, same format as from FING
         getIndigoIPDEvices()
         -- compare to indogo info
         set newDevice to 0
         compareToIndigo(theLOGmacAddress, theLOGIPNumber, theLOGVendor, theLOGStatus, theLOGDate)
      end if
      
   end if
   
   -- check if fingdata was updated (once a minute)
   set cmd to "ls -l " & theDir & theFile & "| awk '{print $8}'" -- time stamp of last change of file
   set thisUpdate to do shell script cmd
   
   if not (thisUpdate = lastUpdate) then -- updated  FINGdata file
      set lastUpdate to thisUpdate -- remember this time stamp
      
      -- read latest fingdata file   
      getFingIPData()
      if noOfDevices > 1 then -- read not successful .. must be more than 1 devices on network
         -- get all devices stored in indigo  into IndigoIpDevices, same format as from FING
         set newDevice to 0
         getIndigoIPDEvices()
         
         -- all data read now compare if anything new
         set ii to 0
         -- loop through FING data
         repeat while ii < noOfDevices
            set ii to ii + 1
            set nextLine to paragraph (ii) of FingContents
            set theItems to every text item of nextLine
            set themacAddress to item 6 of theItems as text
            set theIPNumber to item 1 of theItems as text
            set theStatus to item 3 of theItems as text
            set theDate to item 4 of theItems as text
            set theVendor to item 7 of theItems as text
            --          set theAssignedName to item 5 of theItems as text  -- not used
            --         set theHostName to item 2 of theItems as text -- not used
            
            compareToIndigo(themacAddress, theIPNumber, theVendor, theStatus, theDate)
         end repeat
         
      end if
   end if
   
   -- house keeping, update ipDeviceLastUpdate and reset logfile once a day
   -- update indigo with time stamp and heat beat
   
   if anyChange > 0 then
      try -- just in case indigo is down, dont crash this program
         tell application "IndigoServer"
            set the value of variable "ipDevsLastUpdate" to theTime
         end tell
      end try
   end if
   
   set alive to -alive -- flip everytime fingscan runs
   try -- just in case indigo is down, dont crash this program
      tell application "IndigoServer"
         set the value of variable "ipDevsAlive" to alive
      end tell
   end try
   
   
   return 5 -- idle for 5 seconds
   
end idle



on setupFing()
   global theDir
   global theFile
   global theLog
   global userName
   global theIndigoFolder
   global passwordOption
   global yourPassword
   
   --check if fing is already running, if not start it.
   set theApp to "fing.bin"
   set theResponse to " "
   
   
   
   -- create fing data folder   
   set cmd to "mkdir '" & theDir & "'  >/dev/null  2>&1 & "
   do shell script cmd
   
   -- check if fing.bin is running   
   try
      set theResponse to do shell script "ps aux | grep '" & theApp & "' | awk '{print $2}' "
   end try
   
   -- if pgmToFind is running then theResponse has 3 lines with PIDs from :     ps, fing itself and one more --- have not figured out which one..
   set ii to count words of theResponse
   
   if ii < 3 then -- if not running start script, start fing
      
      
      -- command looks like: "   xx sudo xx   fing -o table,csv,"Users/yourid/Documents/fing/fingdata" log,csv,"Users/yourid/Documents/fing/finglog"  >/dev/null  2>&1 &  " with some variations on  xx sudo xx regarding password depending on option
      -- option 0:      set thePassword in code
      if passwordOption = 0 then
         set cmd to "echo " & yourPassword & " | sudo -S fing  -o table,csv,\"" & theDir & theFile & "\"  log,csv,\"" & theDir & theLog & "\"  >/dev/null  2>&1 &" -- start fing, send to background, dont wait, create 2 output files:  one table format file and one logfile
         set yourPassword to "" -- dont keep password around
      end if
      
      -- option 1:      have to use sudo: pipe password from getPW() into sudo
      if passwordOption = 1 then
         set yourPassword to getPW(userName) -- this has to be looked at, grabs first occurence of userName, if 2 with same username and different passwords this might fail
         set cmd to "echo " & yourPassword & " | sudo -S fing  -o table,csv,\"" & theDir & theFile & "\"  log,csv,\"" & theDir & theLog & "\"  >/dev/null  2>&1 &" -- start fing, send to background, dont wait, create 2 output files:  one table format file and one logfile
         set yourPassword to "" -- dont keep password around
      end if
      
      
      -- option 2:  modify system setting so that fing does not need sudo from gcoop76 indido discussions
      (*
      
      in terminal do:
sudo visudo

add this line:
spanky localhost = NOPASSWD: /usr/bin/fing
That is, if "spanky" is your username (the one who will be executing the applescript and calling fing).

Note that this edits the file in "vi." Use the arrow keys or "j" or "k" to move up and down. Go to the line you want to add the above text and hit "i" for insert. Type or paste it out, then hit "esc." Then hit ":" then type "wq" for "write, then quit"

That should do it. It is important to use visudo to edit your sudoers file since apparently bad things can happen to the permissions of the file if you edit it directly. I just tested it on my Mac OS X Mountain Lion laptop. Works well. Everything else still needs a password for sudo, but not fing.
*)
      if passwordOption = 2 then
         set cmd to " sudo fing -o table,csv,\"" & theDir & theFile & "\"  log,csv,\"" & theDir & theLog & "\"  >/dev/null  2>&1 &" -- start fing, send to background, dont wait, create 2 output files:  one table format file and one logfile
         set yourPassword to "" -- dont keep password around
      end if
      
      --option 3  user will need to enter password      
      if passwordOption = 3 then
         
         tell application "Finder" -- need to go through finder in case this runs in the background
            activate
            set yourPassword to the text returned of (display dialog "FINGSCAN:  enter your password" default answer "xxyyzz" giving up after 200)
         end tell
         set cmd to "echo " & yourPassword & " | sudo -S fing -o table,csv,\"" & theDir & theFile & "\"  log,csv,\"" & theDir & theLog & "\"  >/dev/null  2>&1 &" -- start fing, send to background, dont wait, create 2 output files:  one table format file and one logfile
         set yourPassword to "" -- dont keep password around
      end if
      
      
      -- execute option 0,1,2,3      
      do shell script cmd
      
      delay 10 --wait until FING has finished at least once
      
   end if
   -- fing is running or has started
   
   
   try -- just in case indigo is down, dont crash this program
      set theTime to text -8 thru -1 of ((current date) as «class isot» as string)
      tell application "IndigoServer"
         if not ((exists variable "ipDevsLastUpdate")) then
            make new variable with properties {name:"ipDevsLastUpdate", value:theTime}
         end if
         if not ((exists variable "ipDevsAlive")) then -- heat beat flip everytime it runs
            make new variable with properties {name:"ipDevsAlive", value:"-1"}
         end if
      end tell
   end try
   
   
   return
   
end setupFing


on getIndigoIPDEvices()
   
   global noOfIndigoDevices
   global IndigoIpDevices
   
   -- get all devices stored in indigo  into IndigoIpDevices, same format as from FING
   set AppleScript's text item delimiters to {";"}
   set ii to 0
   set noOfIndigoIpDevices to "0"
   set IndigoIpDevices to {}
   
   set noMore to false
   repeat while ii < 999
      set ii to ii + 1
      set OOii to ii
      if ii < 10 then set OOii to "0" & ii as text
      set ipDevice to "ipDevice" & OOii
      tell application "IndigoServer"
         if not ((exists variable ipDevice)) then
            set noMore to true
            set noOfIndigoDevices to ii - 1 -- this is the number of ipDevices currently in indigo
            set ii to 99999 -- exit repeat
         end if
      end tell
      if noMore = false then
         try -- just in case indigo is down, dont crash this program
            tell application "IndigoServer"
               set ipDeviceValue to (get value of variable ipDevice) as text
            end tell
         end try
         set IndigoIpDevices to IndigoIpDevices & ipDeviceValue -- add next ipDevice to end of list
      end if
   end repeat
   return
end getIndigoIPDEvices


on compareToIndigo(themacAddress, theIPNumber, theVendor, theStatus, theDate) -- this is the data from fing to be compared to indigo
   global noOfIndigoDevices
   global IndigoIpDevices
   global newDevice
   global anyChange
   set anyChange to 1 -- if called there is a change, remember for timestamp variable of last yupdate
   
   -- check if any match in indigo data
   set sameMAC to 0
   set jj to 0
   repeat while jj < noOfIndigoDevices
      set jj to jj + 1
      set nextLineIndigo to item jj of IndigoIpDevices as text
      set theIndigoItems to every text item of nextLineIndigo -- this is all info of ONE indigoIpDevice
      set indigomacAddress to trim(item 2 of theIndigoItems as text) -- this is the indigo mac address for the ipDevice
      if themacAddress = indigomacAddress then ---- mac number found, already in indigo… exit repeat
         set sameMAC to jj -- this is the device that is the same
         set jj to 999999 -- force repeat exit
         set indigoIPNumber to trim(item 3 of theIndigoItems as text) -- get the indigo info for later use
         set indigoStatus to trim(item 5 of theIndigoItems as text)
         set indigoVendor to trim(item 4 of theIndigoItems as text)
         set indigoNick to trim(item 1 of theIndigoItems as text)
         try
            set indigoNoOfChanges to 0 -- make sure that this becomes a number, not text, if empty make it 0
            set indigoNoOfChanges to trim(item 7 of theIndigoItems as text)
            set indigoNoOfChanges to indigoNoOfChanges + 0
         on error
            set indigoNoOfChanges to 0
         end try
         
      end if
   end repeat
   
   
   if sameMAC > 0 then -- found match in MAC number, now check if anything has changed
      
      
      if (theIPNumber = indigoIPNumber) and (theStatus = indigoStatus) then -- both the same
         -- do nothing
      else -- ip or status has changed, update indigo variable
         set OOii to sameMAC
         if sameMAC < 10 then set OOii to "0" & sameMAC as text -- make sequential number 2 digits
         set theDeviceNo to "ipDevice" & OOii -- eg ipDevice06
         set theDeviceValue to indigoNick & ";" & themacAddress & ";" & theIPNumber & ";" & theVendor & ";" & theStatus & ";" & theDate & ";" & indigoNoOfChanges + 1 -- this will be written back to indigo
         try -- just in case indigo is down, dont crash this program
            tell application "IndigoServer"
               set the value of variable theDeviceNo to theDeviceValue
            end tell
         end try
         
      end if
      
   else -- new device, set up    in indigo
      set newDevice to newDevice + 1
      set OOii to noOfIndigoDevices + newDevice
      if OOii < 10 then set OOii to "0" & OOii as text -- make sequential number 2 digits
      set theDeviceName to "ipDevice" & OOii -- eg ipDevice06
      
      set theText to "FINGSCAN network has found new device,  please enter nickname for new device : " & theDeviceName & "  " & themacAddress & "  " & theIPNumber & "  " & theVendor & "  " & theStatus & "   eg:"
      
      tell application "Finder" -- need to go through finder in case this runs in the background
         activate
         set nickname to the text returned of (display dialog theText default answer "phone-xyz" giving up after 60)
      end tell
      
      set theDeviceValue to nickname & ";" & themacAddress & ";" & theIPNumber & ";" & theVendor & ";" & theStatus & ";" & theDate & ";1" -- this will be written back to indigo
      
      try -- just in case indigo is down, dont crash this program
         tell application "IndigoServer"
            make new variable with properties {name:theDeviceName, value:theDeviceValue}
         end tell
      end try
   end if
end compareToIndigo


on getFingIPData()
   
   global noOfDevices
   global FingContents
   global theDir
   global theFile
   set FingContents to {}
   
   -- read latest fingdata file   with unix command cat, tryed normal applescript read, but fing did not like that, this one seems to be less intrucive
   set cmd to "cat " & theDir & theFile
   try
      set FingContents to (do shell script cmd)
      set noOfDevices to (count paragraphs of FingContents)
   end try
   
   return
   
end getFingIPData


on getFingIPlogdata()
   
   global noOfDevices
   global FingContents
   global theDir
   global theFile
   global theLog
   set FingContents to {}
   
   set cmd to "tail -1 " & theDir & theLog -- just get the last line ie the new /changed device only
   try
      set FingContents to (do shell script cmd)
      set noOfDevices to (count paragraphs of FingContents)
   end try
   
end getFingIPlogdata


on getPW(keychainItemName) -- get password from keychain for userid: keychainitemname .. if there are 2 userids that are the same in keychain, it might get the password of the wrong id
   do shell script "security 2>&1 >/dev/null find-generic-password -gl " & quoted form of keychainItemName & " | awk '{print $2}'"
   return (text 2 thru -2 of result) -- return the password part of the string
end getPW


-- trim blanks from string
on trim(someText)
   if someText = "" then return someText
   if someText = " " then return "" -- drop spaces
   
   repeat until someText does not start with " "
      set someText to text 2 thru -1 of someText
   end repeat
   
   repeat until someText does not end with " "
      set someText to text 1 thru -2 of someText
   end repeat
   
   return someText
end trim

Posted on
Fri Sep 13, 2013 8:53 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Using Fing as a new way to detect smartphone presence

Great addition. Why not post it in the File Library where Indigo users can more easily find it? ;)

Also, in order to not hijack Travis' forums, I'm moving this thread over to User Contributions..

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Sep 13, 2013 9:07 am
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

will do

Karl

Posted on
Fri Sep 13, 2013 11:03 am
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

FINGSCAN:

and here is the "official" install of version 1.0

http://www.perceptiveautomation.com/filelib/index.php?id=251


Karl

Posted on
Fri Sep 13, 2013 11:16 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Using Fing as a new way to detect smartphone presence

Great work, Karl. Thanks for sharing it with folks.

Image

Posted on
Sat Sep 14, 2013 2:29 pm
AndrewGWalsh offline
Posts: 67
Joined: Feb 20, 2013

Re: Using Fing as a new way to detect smartphone presence

I'm struggling a little to unzip the download - is anybody else getting a .zip which unzips to a .cpgz which unzips to a .zip and so on back and forth?

Or (quite likely) am I doing something silly?

Andrew

Posted on
Sun Sep 15, 2013 12:49 pm
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

file should be a regular zip ... unzip behavior depends on your unzip program.

do you download from indigo or from copy.com? please use this link:
http://www.perceptiveautomation.com/fil ... php?id=251

if you download from copy.com download the whole folder


EDIT: have the same problem now..
works fine when I use "open with unarchiver" . it should be a regular zip. ... don't really understand this.
end EDIT


Karl

Posted on
Mon Sep 16, 2013 9:04 am
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

Andrew,

has been uploaded again, if you could try again.

sorry for the confusion

Karl

Posted on
Tue Sep 17, 2013 9:24 am
Simon offline
Posts: 32
Joined: Aug 15, 2013
Location: Denmark

Re: Using Fing as a new way to detect smartphone presence

Great add-on :-)


I think I noticed a bug?

If my password contains a "&" it doesn't work.


Thanks for great script :-)

Posted on
Tue Sep 17, 2013 3:58 pm
AndrewGWalsh offline
Posts: 67
Joined: Feb 20, 2013

Re: Using Fing as a new way to detect smartphone presence

Downloaded, installed and happily creating variables....

Thanks for the help :-)

Andrew

Posted on
Tue Sep 17, 2013 4:34 pm
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

regarding & ... looks like applescript does something with the &... this will take a minute


I am on a EU trip and can really check on the server. - back Oct 1.

will try my best.

Karl

Posted on
Tue Sep 17, 2013 5:31 pm
kw123 offline
User avatar
Posts: 8365
Joined: May 12, 2013
Location: Dallas, TX

Re: Using Fing as a new way to detect smartphone presence

Simon,
the fix was -hopefully- easy, tried with & in my password. seems to work. --learned something new.

have asked Jay to upload the fixed version 1.01:
added ' around yourPassword in

do shell script "echo '" &yourPassword&"' | sudo fing ..... "

terminal then sees eg with aBc123&.67 as your password:
echo 'aBc123&.67' | sudo -S fing -o table,csv,"/users/myid/data" log,csv,"/users/myid/log"
The & without the ' around the password pipes the wrong string into sudo. Applescript had no problem

I guess now passwords that contain ' will not work..

Karl

Who is online

Users browsing this forum: No registered users and 7 guests