Quote:
Originally Posted by a thing
Umm... this is the shell forum, not the C forum.
|
If the problem cannot be solved with existing shell tools, then you may need to write your own.
If you just simply want to see if a domain name resolves, you can use something like:
ping $DOMAIN -c1 | grep ^PING | \
awk -F\ '{ gsub( /\(/,// , $3); gsub( /\)/,//,$3 ); print $3 }'
That returns the IP address of the domain. If the domain does not resolve, you get:
ping: unknown host googlaoeuaoee.com
If you do not care what the IP is, you can simply use ping:
#!/bin/bash
ping -c1 $1 >> /dev/null
if [ $? == 2 ]; then
echo "$1 does not exist."
else
echo "$1 exists."
fi
Hope this helps.
