Last active
August 29, 2015 14:10
-
-
Save hex108/da6f0eb45ffa273b9fbb to your computer and use it in GitHub Desktop.
Get IP for specified host using 'http://ping.eu/ping', then write it to hosts.
This file contains hidden or 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 | |
# Get IP for specified host using 'http://ping.eu/ping', then write it to hosts. | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 host" | |
echo " e.g. # $0 baidu.com" | |
exit 0 | |
fi | |
host=$1 | |
ip=$(curl -s -d "host=$host&go=Go" http://ping.eu/action.php?atype=1 | grep "bytes from" | head -n 1 | grep -E -o "([0-9]{1,3}\.){3}[0-9]{1,3}") | |
if [ "$ip" != "" ]; then | |
echo "Writing \"$ip $host\" to /etc/hosts" | |
echo "$ip $host" >> /etc/hosts | |
else | |
echo "Failed to get IP for host \"$host\". Please check it on http://ping.eu/ping/" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment