Page 1 of 1

NMAP problems

Posted: Wednesday 24 January 2018 10:27
by Lebo2d9
Hi,

I have a script using NMAP to detect if a device is online of off line. This script runs every minute.
Some times I get a "falls off" and the next minute the device is back online.

Now i want to create sort of delay that waits 65 sec to turn off the virtual switch.

I dont know how to implement this.
I there someone who can help me to sort this out?

Kind regards

Koen Deschepper

Re: NMAP problems

Posted: Thursday 01 February 2018 23:19
by triton
Don't know if this is useful. I'm checking if my TV is on first by detecting a change in the power consumption. Second I don't know if the TV is on or the Receiver I use the tcp_connect function below to try and connect to port 80 on the tv. If i can connect the TV is on and I switch a device on. Same in reverse, if I can't connect the TV must be off.

You need the socket lib, see instructions here: http://www.domoticz.com/wiki/Upload_ene ... et_library

Second, I'm using this function:

Code: Select all

function tcp_connect(host, port)
    -- v1.0. 2017-03-21
    -- attempt TCP connection to a host and port
    -- USAGE   : succes = tcp_connect(localhost, 8080)
    -- RETURNS : nil or tcp socket
    --
    local socket = require("socket")
    local tcp = socket.tcp()
    tcp:settimeout(2) -- 2s timeout, domoticz timewindow is 10 seconds.
    local client = tcp:connect(host, port)
    return client
end
To get an idea for the usage (ignore the watts, just the idea of the tcp_connect function):

Code: Select all

if (watts > 150 and otherdevices['TV'] == 'Off') then
   local result = tcp_connect('192.168.0.18', 80)
   if (result) then
      commandArray['TV'] = 'On'
   end
end      

Re: NMAP problems

Posted: Friday 02 February 2018 11:15
by aalwash
Just an idea

Maybe add a variable, that is updated when the "first" time the TV is been detected "not responding"
The second time, you check the if the variable is on "Off" and when did this happen (timestamp).
If this is longer then 65sec ago, then put the switch to 'Off'.

If not, don't do anything, the next run will do the same check.