Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: Why does this domain not resolve?

Tags:

c#

.net

dns

I am trying to programmatically test if a given domain name exists.

The following line of code works as expected:

IPHostEntry IPhst =Dns.GetHostEntry("google.com");

But it fails for some few domains on the very same host at the very same time. For example, the following throws an exception.

IPHostEntry IPhst =Dns.GetHostEntry("bks-campus.ch");

The resulting exception is identical to exceptions that are thrown when the domain name does not exist at all.

The weird thing is that the domain actually exists. I am able to browse it from the same machine that just ran the code above.

What might be the problem here and how can I work around this?

Edit: Dig also agrees that this domain name actually exists:

dig bks-campus.ch

; <<>> DiG 9.5.0-P2 <<>> bks-campus.ch
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14744
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0

;; QUESTION SECTION:
;bks-campus.ch.                 IN      A

;; AUTHORITY SECTION:
bks-campus.ch.          3600    IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400

;; Query time: 1214 msec
;; SERVER: 192.168.0.1#53(192.168.0.1)
;; WHEN: Fri Jul  2 12:50:10 2010
;; MSG SIZE  rcvd: 94
like image 526
Adrian Grigore Avatar asked Dec 09 '22 15:12

Adrian Grigore


2 Answers

; <<>> DiG 9.3.2 <<>> any bks-campus.ch @olympus
; (1 server found)
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1406
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;bks-campus.ch.                 IN      ANY

;; ANSWER SECTION:
bks-campus.ch.          86400   IN      SOA     dns1.bks-campus.ch. hostmaster.kanti-chur.ch. 1275546863 10800 3600 604800 86400
bks-campus.ch.          86400   IN      MX      20 cws02.netgrouper.ch.
bks-campus.ch.          86400   IN      MX      20 cws01.netgrouper.ch.
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; AUTHORITY SECTION:
bks-campus.ch.          86400   IN      NS      dns1.bks-campus.ch.

;; ADDITIONAL SECTION:
cws02.netgrouper.ch.    32548   IN      A       194.150.160.32

;; Query time: 179 msec
;; SERVER: 192.168.2.4#53(192.168.2.4)
;; WHEN: Fri Jul 02 13:00:48 2010
;; MSG SIZE  rcvd: 193

There are no A (IPv4) records for bks-campus.ch, neither any CNAME (alias) or AAAA (IPv6). The response only tells us which servers handles mail (MX), dns (NS) and some administrative record (SOA). There's nothing in the response that tells the resolver where to find bks-campus.ch. Add an A record (or CNAME) and it will work.

like image 180
sisve Avatar answered Dec 29 '22 03:12

sisve


google.com has an A record associating it with an IP address. bks-campus.ch does not have any A, AAAA or CNAME records, so you get an error.

Your browser is probably automatically adding the www when it can't find an A record for the domain.


Edit: Your dig output confirms that bks-campus.ch exists but has no A record.

like image 27
Phil Ross Avatar answered Dec 29 '22 04:12

Phil Ross