Skip to content

Instantly share code, notes, and snippets.

@hex108
Last active August 29, 2015 14:10
Show Gist options
  • Save hex108/da6f0eb45ffa273b9fbb to your computer and use it in GitHub Desktop.
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.
#!/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