View Single Post
Old Oct 3rd, 2006, 10:11 AM   #7
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
Quote:
Originally Posted by a thing View Post
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.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote