ping to win10 not possible: build script that uses nmap

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
Maikel76
Posts: 71
Joined: Friday 14 August 2020 6:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Bangkok
Contact:

ping to win10 not possible: build script that uses nmap

Post by Maikel76 »

Hi,
Just made a short bash script to made it possible again to check if my wifes laptop was on or not. Before I used the Alive plugin but thats not working after one of those glorious windows updates
This script uses nmap. You first need to install this. I tested this on raspberry pi 3B

Code: Select all

sudo apt-get update
sudo apt-get install nmap
then make a script with nano or vi, i made a dir for this under domoticz/scripts but you can put it somehere else too;

Code: Select all

nano devup.sh
input the following

Code: Select all

 #!/bin/bash
 adres=$1
 # example hostdown=`nmap -sP 192.168.88.182 | grep "Host seems down" | wc -l`
 hostdown=`sudo nmap -sP $adres | grep "Host seems down" | wc -l`
 hostup=`sudo nmap -sP $adres | grep "Host is up" | wc -l`
 if [[ "$adres" = "-help" ]]; then
         echo "type ip-address as parameter"
 fi
 if [[ "$hostup" = "1" ]]; then
         echo -n "up"
 elif [[ "$hostup" = "0" ]]; then
         if [[ "$hostdown" = "1" ]]; then
                 echo -n "down"
         elif [[ "$hostdown" = "0" ]]; then
                 echo -n "error"
         fi
 fi
then make the script exacutable and change owner

Code: Select all

sudo chmod +x ./devup.sh
sudo chown pi:pi ./devup.sh
then in domoticz make a dvVents script and paste the following

Code: Select all

return {
	on = {
		devices = {},
		timer = {'every 5 minutes'},
		variables = {},
		scenes = {},
		groups = {},
		security = {},
		httpResponses = {},
		shellCommandResponses = {},
		customEvents = {},
		system = {},
	},
	data = {},
	logging = {},
	execute = function(domoticz, triggeredItem)
        local ltearnip='192.168.12.123'
        local ltearn=domoticz.devices('LaptopEarn')    -- laptop earn
        local command = '/home/pi/domoticz/scripts/bashscrips/devup.sh '..ltearnip
	    local handle = io.popen(command)
        local updated = handle:read("*a")
        handle:close()
        domoticz.log('ltearn: '..updated)
        if (updated == 'up') then
            ltearn.switchOn().checkFirst()
        elseif (updated == 'down') then
            ltearn.switchOff().checkFirst()
        end --endif    
	end
}
It would be better to use shellCommandResponses but i wanted to make it quick, if anyone can rebuild i would apreciate that you post it here

if there is a way to change the current Alive checker I would gladly help
Scripting is my passion, dzVents, LUA, Bash
Dashticz v3.10.7 Beta --Raspbian Buster
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests