blob: 47fcfdb2d38999d19f45fe6885229bfc02d73cd4 [file] [log] [blame]
#!/bin/selfclean sh
# Periodically send queries for hostnames, and store the results in
# files in /tmp. Send queries for taxonomy information, and log the
# results. Most of these utilities are blocking and wait for a
# few seconds, and would slow down catawampus to call them directly.
. /etc/utils.sh
DNSSD_FILE="/tmp/dnssd_hostnames"
NETBIOS_FILE="/tmp/netbios_hostnames"
SLEEP=397
RECENT=512
remove_new_from_old() {
new="$1"
oldfilename="$2"
if [ -e "$oldfilename" ]; then
while IFS="|" read addr host; do
if ! contains "$new" "$addr"; then
echo "$addr|$host"
fi
done < "$oldfilename"
fi
}
update_dnssd_names() {
if runnable dnssd_hosts; then
new=$(dnssd_hosts | sort | uniq)
if [ ! -z "$new" ]; then
old=$(remove_new_from_old "$new" "$DNSSD_FILE")
hosts=$(echo "$new" "$old" | head -n $RECENT)
atomic "$DNSSD_FILE" "$hosts"
fi
fi
}
update_netbios_names() {
if runnable netbios_hosts; then
new=$(netbios_hosts | sort | uniq)
if [ ! -z "$new" ]; then
old=$(remove_new_from_old "$new" "$NETBIOS_FILE")
hosts=$(echo "$new" "$old" | head -n $RECENT)
atomic "$NETBIOS_FILE" "$hosts"
fi
fi
}
update_asustax() {
if runnable asustax; then
asustax 2>&1 | head -n "$RECENT" | logos taxonomy
fi
}
update_ssdptax() {
if runnable ssdptax; then
ssdptax 2>&1 | head -n "$RECENT" | logos taxonomy
fi
}
update_dnssd_names
sleep 1
update_netbios_names
sleep 1
update_asustax
sleep 1
update_ssdptax
while [ true ]; do
sleep "$SLEEP"
update_dnssd_names
sleep "$SLEEP"
update_netbios_names
sleep "$SLEEP"
update_asustax
sleep "$SLEEP"
update_ssdptax
done
exit 0