1

When doing a bulk input of records, I want to verify that I put each in its correct location by doing a bulk query with dig. Dig will spit out all positive results with:

dig +noall +answer

or

dig +short

And it gets even closer as noted in an answer to another question:

dig +noall +question +answer

But this still shows all "positive" output, making you search through the bulk output for two semicolons in a row at the start of the line to identify records that return nothing.

What I am looking for is a command (doesn't have to be Dig) that will return only the errors or only indicate the records with no results, such that only those are displayed, not the typical output of correctly entered records.

Watki02
  • 537
  • 2
  • 12
  • 21

2 Answers2

1

Many ways to do this... just some simple scripting. Even a Python response in the question you referenced.

  • Invoke DIG multiple times instead of just once with bulk file. That returns 1 line fail, 2 or more lines good. Echo name based on pass/fail.

  • Use you favorite script language's DNS lookup method and evaluate return code. I like powershell, and for that you would use [System.Net.Dns]::GetHostByAddress("fully.qualified.domain.name")

  • Invoke DIG once with bulk file, and regex the output (regular expressions). Sample below, again in powershell. If you're a unix guy, regex is there too. I used SED many many years ago, but there are probably easier ways these days.

zz

[string]$digout = dig +noall +answer +question goodname1 goodname2 badname1 goodname3 badname2
$digout = $digout -replace ("\r\n", "")
$digout.split(";") | select-string -notmatch "\d\s+IN"

Will return:

badname1.            IN    A
badname2.            IN    A

1st line assigns DIG output to a var as a string NOT an array. This is needed because regex works on strings and not arrays. 2nd line removes CR/LF from that var. Part 3A line splits var so that each question and it's answer appears on same line. Part 3B filters that text so that only questions without an answer are shown.

Clayton
  • 4,483
  • 16
  • 24
0

This sort of thing will be much easier in a scripting language. For instance, in Python, a faulty lookup will throw an exception:

Python 3.5.1 (default, Mar  3 2016, 09:29:07) 
[GCC 5.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> socket.gethostbyname('google.com')
'216.58.216.78'
>>> socket.gethostbyname('alsdkfjowiejlskdjf.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.gaierror: [Errno -2] Name or service not known

so then it's just a matter of doing all your lookups and only printing out results that land in your try-catch.

Xiong Chiamiov
  • 2,874
  • 2
  • 26
  • 30