Skip to content

Instantly share code, notes, and snippets.

@jpatel531
Created November 3, 2014 17:08
Show Gist options
  • Save jpatel531/d8ab8c6e41abbc63d4cf to your computer and use it in GitHub Desktop.
Save jpatel531/d8ab8c6e41abbc63d4cf to your computer and use it in GitHub Desktop.
'Who's In?' Local Scanner
#!/bin/bash
APP_PASSWORD="bar"
WHOSIN_URL=$1
AUTH_KEY=$2
local_scan() {
macs=( $(sudo nmap -sn 192.168.1.0/24 | grep -Eio "([0-9A-F]{2}:){5}[0-9A-F]{2}") )
}
update_offline_since() {
local json=()
local DATE=$(date)
for i in "${!macs[@]}"; do
json[$i]="{\"mac\": \"${macs[$i]}\"}"
done
json=$( IFS=, ; echo "${json[*]}")
json="[$json]"
curl -X POST -d "$json" $WHOSIN_URL -u admin:$AUTH_KEY >/dev/null 2>&1
}
local_scan
if [ ${#macs[@]} -eq 0 ]; then
echo "{'error': 'Nobody here'}"
else
update_offline_since
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment