Created
September 27, 2013 09:24
-
-
Save honzajavorek/6726141 to your computer and use it in GitHub Desktop.
Kraken's IP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTS="/etc/hosts" | |
MOUNT_DIR="/home/honza/.kraken" | |
kraken_ip="" | |
lan=(`nmap -sP 192.168.1.* | grep 192 | sed -e s/[^0-9\.]//g`) | |
for ip in "${lan[@]}"; do | |
if curl -s "http://$ip" | grep -q "ShareCenter" | |
then | |
echo "Kraken's IP: $ip" | |
hosts_ip=`cat "$HOSTS" | grep "kraken" | sed -e s/[^0-9\.]//g` | |
if [[ "$ip" != "$hosts_ip" ]] | |
then | |
echo "Kraken's IP has changed! ($hosts_ip -> $ip)" | |
echo "Editing hosts file." | |
sed -e "s/$hosts_ip/$ip/" -i "$HOSTS" | |
echo "Detaching filesystem." | |
umount -f "$MOUNT_DIR" | |
echo "Attaching all filesystems." | |
mount -a | |
fi | |
kraken_ip="$ip" | |
break | |
fi | |
done | |
if [[ ! "$kraken_ip" ]] | |
then | |
echo "Kraken's IP address not found." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment