[3783] | 1 | #!/bin/sh
|
---|
| 2 | #
|
---|
| 3 | # dubbelipcheck.sh
|
---|
| 4 | # Scriptje om in de wleiden.conf files van Wireless Leiden
|
---|
| 5 | # te controleren of er geen dubbele ip addressen bestaan
|
---|
| 6 | #
|
---|
| 7 | # Rick van der Zwet (rick@wirelessleiden.nl)
|
---|
[8859] | 8 | genesis_nodes_dir="`dirname $0`/../nodes"
|
---|
[7993] | 9 | allowed_dubbel_ip="172.31.255.1 172.31.255.2 192.168.1.[0-9]\{1,3\} 0.0.0.0"
|
---|
[7298] | 10 | TMPDIR=`mktemp -d -t $(basename $0 .sh).XXXXX`
|
---|
[3783] | 11 |
|
---|
[7254] | 12 | ERRNO=0
|
---|
| 13 |
|
---|
[3783] | 14 | #zoek alle ip address in de files op
|
---|
| 15 | init()
|
---|
| 16 | {
|
---|
| 17 | files=`find $genesis_nodes_dir/*/wleiden.conf | grep -e "[A-Z]Node\|proxy"`
|
---|
| 18 |
|
---|
| 19 | master_ips=`cat $files | grep '^$master_ip' |\
|
---|
[7927] | 20 | sed -e 's/[^0-9]*\([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*$/\1/'`
|
---|
[3783] | 21 | link_ips=`cat $files | grep ^IP | grep -v '$master_ip' |\
|
---|
[7927] | 22 | sed -e 's/IP=//' -e 's/\/[0-9]*//' -e 's/[[:space:]]*$//'`
|
---|
[7460] | 23 | echo "$master_ips $link_ips" | sort
|
---|
[7298] | 24 | echo "$master_ips $link_ips" | sort > $TMPDIR/all_ips
|
---|
| 25 | echo "$master_ips $link_ips" | sort -u > $TMPDIR/all_ips_no_double
|
---|
[3783] | 26 | }
|
---|
| 27 |
|
---|
| 28 |
|
---|
| 29 | #check up dubbele ip addressen
|
---|
| 30 | dubbelIpCheck() {
|
---|
[7298] | 31 | dubbel_ips=`comm -23 $TMPDIR/all_ips $TMPDIR/all_ips_no_double | sort -u`
|
---|
[3783] | 32 | }
|
---|
| 33 |
|
---|
| 34 |
|
---|
[6891] | 35 | #verwijder toegestane dubbele ip's
|
---|
| 36 | verwijderToegestaneIps() {
|
---|
[3783] | 37 | for allowed in $allowed_dubbel_ip; do
|
---|
| 38 | dubbel_ips=`echo $dubbel_ips | sed s/$allowed//`
|
---|
| 39 | done
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 |
|
---|
| 43 | #print resultaten
|
---|
| 44 | results() {
|
---|
| 45 | if [ "$dubbel_ips" ]; then
|
---|
| 46 | for dubbel_ip in $dubbel_ips ; do
|
---|
[7254] | 47 | ERRNO=1
|
---|
[3783] | 48 | echo ""
|
---|
| 49 | echo "Dubbel ip gevonden: $dubbel_ip"
|
---|
| 50 | echo "Wordt gebruikt in:"
|
---|
| 51 | for file in $files ; do
|
---|
[9479] | 52 | grep -v '#' $file | grep "$dubbel_ip" | grep "^IP\|^$master_ip" > /dev/null && echo " -$file"
|
---|
[3783] | 53 | done
|
---|
| 54 | done
|
---|
| 55 | else
|
---|
| 56 | echo "Geen dubbele ip's gevonden"
|
---|
| 57 | fi
|
---|
| 58 | echo ""
|
---|
[6891] | 59 | echo "Toegestane dubbele ip's:"
|
---|
[3783] | 60 | for ip in $allowed_dubbel_ip ; do
|
---|
| 61 | echo " -$ip"
|
---|
| 62 | done
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 |
|
---|
| 66 | #verwijder tijdelijke files
|
---|
| 67 | cleanup() {
|
---|
[7298] | 68 | rm -R $TMPDIR
|
---|
[3783] | 69 | }
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 |
|
---|
| 73 | #hoofdmodule
|
---|
| 74 | main() {
|
---|
| 75 | init
|
---|
| 76 | dubbelIpCheck
|
---|
[6891] | 77 | verwijderToegestaneIps
|
---|
[3783] | 78 | results
|
---|
| 79 | cleanup
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | main
|
---|
[7254] | 83 | exit $ERRNO
|
---|
[3783] | 84 |
|
---|