Sha256: f3730c85c8280a22ed2bff8254fc82bc0e9144b6ad9d8745f8f55cb10185667c

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

#!/bin/sh

hostnames="\
	officecdn.microsoft.com						\
	officecdn.microsoft.com.edgesuite.net				\
	ctldl.windowsupdate.com						\
	niig4.ocsp.secomtrust.net					\
	repo1.secomtrust.net						\
	scrootca2.ocsp.secomtrust.net					\
	repository.secomtrust.net					\
	wpad.tottori-u.ac.jp						\
	"
filename=ipaddrs.txt

#
tmpfile=$filname.tmp
interval=300
expiry=864000

log()
{

	echo `date '+%Y/%m/%d %H:%M:%S'` "$1"
}

resolve()
{
	hostname=$1

	host $hostname | sed -rn 's/^.* has address ([0-9.]+)$/\1/p'
}

add()
{
	ia=$1
	hostname=$2
	time=$3

	if ! remove $ia $hostname 'no'; then
		log "add $hostname ($ia) $time"
		r=0
	else
		r=1
	fi
	echo "$ia $hostname $time" >> $filename
	return $r
}

remove()
{
	ia=$1
	hostname=$2
	removeonly=$3

	[ ! -e $filename ] && return
	if [ "$removeonly" = 'yes' ]; then
		log "Remove $hostname ($ia)"
	fi
	grep "^$ia .*$" $filename > /dev/null 2>&1
	r=$?
	if [ $r -eq 0 ]; then
		grep -v "^$ia .*$" $filename > $tmpfile
		mv $tmpfile $filename
	fi
	return $r
}

expire()
{
	now=$1
	expiry=$2

	while read ia hostname lasttime; do
		diff=`expr $now - $lasttime`
		if [ $diff -gt $expiry ]; then
			remove $ia $hostname 'yes'
		fi
	done < $filename
}

log 'Started'
while true; do
	changed=no
	now=`date +%s`
	for h in $hostnames; do
		for ia in `resolve $h`; do
			if add "$ia" "$h" "$now"; then
				changed=yes
			fi
		done
	done
	expire $now $expiry
	if [ "$changed" = 'yes' ]; then
		ruby wiredlanauth-filter-sync.rb
	fi
	sleep $interval
done

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
netutils-0.1.2 bin/ipaddr-resolv.sh
netutils-0.1.1 bin/ipaddr-resolv.sh