Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Bash / Shell Scripting (http://www.programmingforums.org/forum26.html)
-   -   domain existence (http://www.programmingforums.org/showthread.php?t=11417)

a thing Sep 27th, 2006 11:25 PM

domain existence
 
How could I check if a DNS domain exists? dig doesn't work because my DNS servers (OpenDNS) return the IP of their search server.

jim mcnamara Sep 28th, 2006 3:27 PM

Do you want to check the existence of any domain - nslookup?
Options let you specify a domain to limit the search. You can also specify the
DNS box.

I'm not sure what you meant by a DNS domain in this context....

a thing Sep 28th, 2006 6:34 PM

nslookup isn't what I want, but its man page pointed me to host, which is exactly what I wanted.

a thing Sep 29th, 2006 12:54 AM

:/ host doesn't handle LAN IPs or aliases in /etc/hosts.

sarumont Sep 29th, 2006 12:19 PM

Check out 'man gethostbyname'. I believe that this library uses the standard DNS lookup stack in *nix (typically in /etc/host.conf).

a thing Sep 29th, 2006 6:50 PM

Umm... this is the shell forum, not the C forum.

sarumont Oct 3rd, 2006 10:11 AM

Quote:

Originally Posted by a thing (Post 115323)
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. :cool:

a thing Oct 3rd, 2006 8:11 PM

Quote:

Originally Posted by me
my DNS servers (OpenDNS) return the IP of their search server

:

notroot@arthur[0:~]$ ping -c1 asdr.ear.baawer
PING asdr.ear.baawer (208.67.219.40) 56(84) bytes of data.
64 bytes from ip-208-67-219-40.n.opendns.com (208.67.219.40): icmp_seq=1 ttl=50 time=14.1 ms

--- asdr.ear.baawer ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 14.197/14.197/14.197/0.000 ms
notroot@arthur[0:~]$ echo $?
0
notroot@arthur[0:~]$


sarumont Oct 3rd, 2006 10:17 PM

Quote:

Originally Posted by a thing (Post 115720)
:

notroot@arthur[0:~]$ ping -c1 asdr.ear.baawer
PING asdr.ear.baawer (208.67.219.40) 56(84) bytes of data.
64 bytes from ip-208-67-219-40.n.opendns.com (208.67.219.40): icmp_seq=1 ttl=50 time=14.1 ms

--- asdr.ear.baawer ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 14.197/14.197/14.197/0.000 ms
notroot@arthur[0:~]$ echo $?
0
notroot@arthur[0:~]$


That clears things up a bit. Whether the domain exists or not has no bearing on OpenDNS's reply. That is quite crappy. Short of using your own DNS servers (or your ISP's), putting two and two together should work for you:

-'host' can resolve the IP of any FQDN given it
-'ping' can resolve the IP of any local DN (that you may specify in /etc/hosts)

host + ping + glue = solution ;)

Edit:

Playing around a bit more with OpenDNS as my nameserver, it appears to only return its search server IPs when the domain is not found. This being the case, you can still solve this with one tool (ping) and some parsing of the results (if $IP is in $IPS_OWNED_BY_OPENDNS....). :cool:

a thing Oct 3rd, 2006 10:38 PM

Your proposed solution has given me a better idea. Ping gives the packet loss percent. All I need to do is check if that's like <=15.

Damn I should learn awk.


All times are GMT -5. The time now is 9:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC