dig interview questions
Top dig frequently asked interview questions
I want to find out all the subdomains of a given domain. I found a hint which tells me to dig the authoritative Nameserver with the following option:
dig @ns1.foo.bar some_domain.com axfr
But this never works. Has anyone a better idea/approach
Source: (StackOverflow)
What am I doing wrong?
This works:
ns="ns.nameserver.co.uk"
d="domain.co.uk"
dig @$ns $d A | grep $d
However using just a variable after pipe does not (it hangs):
ns="ns.nameserver.co.uk"
d="domain.co.uk"
g=$(grep $d | grep -v "DiG")
dig @$ns $d A | $g
Do I need to do something special after the pipe so it knows to run the grep command from the g variable? Using backticks (historic) fails as well.
Source: (StackOverflow)
Just a forewarning, my python skills are almost nonexistent, but I’m trying to learn as I go.
I'm doing a few changes via our DNS control panel over the weekend to about 58 CNAMES (just changing the destination)
And rather than checking the changes have gone live for each individual record I was wondering if there was a way to script a list of digs for each CNAME in python?
The dig command I use would be something like this
dig @ns1.netnames.net www.rac.co.uk CNAME
and I would expect to see rac-secure.gslb2.rac.co.uk
returned.
I tried something like:
import os
os.system( 'dig<exampledomain.com>'CNAME )
But that didn't appear to work (as I mentioned my python skills are lacking), am I on the right path, or should I be using something like dnspython? I have used the dnspython module before with (a lot) of help from the stack overflow community but I find the documentation really confusing.
Any pointers in the right direction would be greatly appreciated.
Regards
Chris.
Source: (StackOverflow)
Here is the ANSWER SECTION when I run dig www.google.com
:
;; ANSWER SECTION:
www.google.com. 108 IN A 74.125.239.115
www.google.com. 108 IN A 74.125.239.114
www.google.com. 108 IN A 74.125.239.116
www.google.com. 108 IN A 74.125.239.113
www.google.com. 108 IN A 74.125.239.112
I think the first field contains the URL and the second field contains the port number. I am not sure about the third and fourth fields. I think the fifth field contains the IP address.
I've reviewed http://www.madboa.com/geek/dig/ and https://kb.mediatemple.net/questions/909/Understanding+the+dig+command, and am still unsure what each section represents.
Source: (StackOverflow)
I am trying to find the gmail.com mail server using dig command and verifying the results returned by dig command using telnet.
$ dig gmail.com MX
; <<>> DiG 9.7.3 <<>> gmail.com MX
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54145
;; flags: qr rd ra; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;gmail.com. IN MX
;; ANSWER SECTION:
gmail.com. 800 IN MX 10 alt1.gmail-smtp-in.l.google.com.
gmail.com. 800 IN MX 20 alt2.gmail-smtp-in.l.google.com.
gmail.com. 800 IN MX 30 alt3.gmail-smtp-in.l.google.com.
gmail.com. 800 IN MX 40 alt4.gmail-smtp-in.l.google.com.
gmail.com. 800 IN MX 5 gmail-smtp-in.l.google.com.
;; Query time: 14 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Tue Dec 27 02:09:50 2011
;; MSG SIZE rcvd: 150
Dig command says "alt1.gmail-smtp-in.l.google.com" is one of the mail server. The smtp ports 25 or 587 is not opened(verified using telnet) for the link "alt1.gmail-smtp-in.1.google.com". However the link http://support.google.com/mail/bin/answer.py?hl=en&answer=13287 says that smtp.gmail.com is the mail server for gmail.com and the port 587 opens for it. Why dig is giving wrong email servers or where my understanding in reading dig output is going wrong.
Source: (StackOverflow)
This command returns my ip address with additional information.
dig @resolver1.opendns.com myip.opendns.com
; <<>> DiG 9.6-ESV-R4-P3 <<>> @resolver1.opendns.com myip.opendns.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48206
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;myip.opendns.com. IN A
;; ANSWER SECTION:
myip.opendns.com. 0 IN A 122.167.119.178
;; Query time: 199 msec
;; SERVER: 208.67.222.222#53(208.67.222.222)
;; WHEN: Fri May 18 11:46:51 2012
;; MSG SIZE rcvd: 50
I only want to extract my ip address from this. How can I extract my ip address from the dig
output?
Source: (StackOverflow)
Would it be possible to check a domain name its existence by checking the output of "dig"?
Inside the bind sources I found these constants:
0 DNS_R_NOEROR
1 DNS_R_FORMERR
2 DNS_R_SERVFAIL
3 DNS_R_NXDOMAIN
4 DNS_R_NOTIMP
5 DNS_R_REFUSED
6 DNS_R_YXDOMAIN
7 DNS_R_YXRRSET
8 DNS_R_NXRRSET
9 DNS_R_NOTAUTH
10 DNS_R_NOTZONE
16 DNS_R_BADVERS
<RCODE 11> # 11 has no macro
<RCODE 12> # 12 has no macro
<RCODE 13> # 13 has no macro
<RCODE 14> # 14 has no macro
<RCODE 15> # 15 has no macro
In my opinion NOERROR & SERVFAIL means the hostname exists (although it doesn't mean an ip is linked to it). NXDOMAIN would mean it absolutely not exists.
I prefer not to use whois because it is quite slow. dig is much faster as I just need to be certain that the hostname doesn't exist yet.
Could someone shine their light on my assumptions and the other macros?
Thanks
Source: (StackOverflow)
h = {
data: {
user: {
value: "John Doe"
}
}
}
To assign value to the nested hash, we can use
h[:data][:user][:value] = "Bob"
However if any part in the middle is missing, it will cause error.
Something like
h.dig(:data, :user, :value) = "Bob"
won't work, since there's no Hash#dig=
available yet.
To safely assign value, we can do
h.dig(:data, :user)&.[]=(:value, "Bob") # or equivalently
h.dig(:data, :user)&.store(:value, "Bob")
But is there better way to do that?
Source: (StackOverflow)
I wanna convert a list of domain to the IP address using bash scripts in OSX.
I created a list file to present the domain line by line like this
www.google.com
www.yahoo.com
www.facebook.com
I used the following scripts to lookup the IP address:
#!/bin/bash
while read -r domain
do
echo `dig +short $domain`
done < list
where list is a file that contains those domain.
However, it end up only show a empty string.
But when I only query one domain, the command is okay.
dig +short www.google.com
> 216.58.221.132
Hope anyone can help me to figure out the problem. Thanks!
Source: (StackOverflow)
I have this MX output in $ip
:
10 ASPMX2.GOOGLEMAIL.COM. 10 ASPMX3.GOOGLEMAIL.COM. 1 ASPMX.L.GOOGLE.COM. 5 ALT1.ASPMX.L.GOOGLE.COM. 5 ALT2.ASPMX.L.GOOGLE.COM.
The number is the priority and the subdomain is the mail server. How could I stored them in array like this:
Array
(
[0] => Array
(
[0] => 10
[1] => ASPMX2.GOOGLEMAIL.COM.
)
[1] => Array
(
[0] => 10
[1] => ASPMX3.GOOGLEMAIL.COM.
)
...
)
The hard part is the whole output could be anything. I mean the mail server subdomain name and the number of server could be random. In the above is 5 mail server but it could be 3 or just 1 server (not to be confuse with mail server priority number).
I'm thinking about preg_match
, but the random subdomain name just leaves me clueless. Any idea?
Source: (StackOverflow)
Is it possible to lookup the A (ip address) and NS (nameservers) of a domain using a single dig command?
I can use dig google.com A +short or dig google.com NS +short but surely it's possible to do it with just one command? If not, is there a similar command that might be able to do this?
Thank you
Source: (StackOverflow)
I have an awk command to extract information from mount points (see the accepted answer in How to extract NFS information from mount on Linux and Solaris?):
awk -F'[: ]' '{if(/^\//)print $3,$4,$1;else print $1,$2,$4}
I would like to include a dig lookup in this awk
command to lookup the IP of hostnames. Unfortunately, the mount command sometimes include an IP and sometimes a hostname. I tried the following, but it has an unwanted newline, unwanted return code and does not work if there is an IP address:
For hostnames
echo "example.com:/remote/export on /local/mountpoint otherstuff" | awk -F'[: ]' '{if(/^\//)print system("dig +short " $3),$4,$1;else print system("dig +short " $1),$2,$4}'
Returns
93.184.216.119
0 /remote/export /local/mountpoint
For IPs
echo "93.184.216.119:/remote/export on /local/mountpoint otherstuff" | awk -F'[: ]' '{if(/^\//)print system("dig +short " $3),$4,$1;else print system("dig +short " $1),$2,$4}'
Returns
0 /remote/export /local/mountpoint
I would like to retrieve the following in both cases
93.184.216.119 /remote/export /local/mountpoint
Update:
It seems that some versions of dig
return the IP when an IP is provided as query and others return nothing.
Solution:
Based on the accepted answer I used the following adapted awk
command:
awk -F'[: ]' '{if(/^\//) { system("dig +short "$3" | grep . || echo "$3" | tr -d \"\n\""); print "",$4,$1 } else { system("dig +short "$1" | grep . || echo "$1" | tr -d \"\n\"");print "",$2,$4 };}'
The additional grep . || echo "$3"
takes care that the input IP/hostname is returned if dig returns nothing.
Source: (StackOverflow)
I'm looking for an OWL-DL reasoner that provides an .NET API.
Alternatively I could use a DIG compliant reasoner written in any language, but
i need a .NET library that is able to convert OWL ontologies into DIG XML language.
Anyone heard about such tools/libraries?
Source: (StackOverflow)
I am trying to reverse dns a list of IPs using socket.gethostbyaddr() in python, which returns 'Unknown Host' for some values, but using dig for the same ip returns the Hostname. Also, dig seems to be significantly faster than using python module, is there any specific reasons for that?
import socket
# This returns 'Unknown Host'
name, alias, addresslist = socket.gethostbyaddr('114.143.51.197')
Source: (StackOverflow)
I trying use dns python
and want get all records with ANY
type query:
import dns.name
import dns.message
import dns.query
domain = 'google.com'
name_server = '8.8.8.8'
domain = dns.name.from_text(domain)
if not domain.is_absolute():
domain = domain.concatenate(dns.name.root)
request = dns.message.make_query(domain, dns.rdatatype.ANY)
response = dns.query.udp(request, name_server)
print response.answer
print response.additional
print response.authority
but it return me
[]
[]
[]
When I try make this request with dig
:
$ dig @8.8.8.8 google.com -t ANY
; <<>> DiG 9.9.2-P1 <<>> @8.8.8.8 google.com -t ANY
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2848
;; flags: qr rd ra; QUERY: 1, ANSWER: 25, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;google.com. IN ANY
;; ANSWER SECTION:
google.com. 299 IN A 173.194.40.14
google.com. 299 IN A 173.194.40.1
google.com. 299 IN A 173.194.40.7
google.com. 299 IN A 173.194.40.4
google.com. 299 IN A 173.194.40.3
google.com. 299 IN A 173.194.40.0
google.com. 299 IN A 173.194.40.8
google.com. 299 IN A 173.194.40.6
google.com. 299 IN A 173.194.40.5
google.com. 299 IN A 173.194.40.2
google.com. 299 IN A 173.194.40.9
google.com. 299 IN AAAA 2a00:1450:4002:804::1000
google.com. 21599 IN TYPE257 \# 23 0009697373756577696C6473796D616E7465632E636F6D
google.com. 21599 IN TYPE257 \# 19 0005697373756573796D616E7465632E636F6D
google.com. 21599 IN NS ns2.google.com.
google.com. 21599 IN NS ns3.google.com.
google.com. 599 IN MX 50 alt4.aspmx.l.google.com.
google.com. 599 IN MX 10 aspmx.l.google.com.
google.com. 3599 IN TXT "v=spf1 include:_spf.google.com ip4:216.73.93.70/31 ip4:216.73.93.72/31 ~all"
google.com. 599 IN MX 20 alt1.aspmx.l.google.com.
google.com. 21599 IN SOA ns1.google.com. dns-admin.google.com. 2013070800 7200 1800 1209600 300
google.com. 599 IN MX 30 alt2.aspmx.l.google.com.
google.com. 21599 IN NS ns1.google.com.
google.com. 599 IN MX 40 alt3.aspmx.l.google.com.
google.com. 21599 IN NS ns4.google.com.
;; Query time: 52 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Jul 16 18:23:46 2013
;; MSG SIZE rcvd: 623
When I check requests with wireshark
then found that dig
and dns python
have different requests:
dig
:
0000 c8 64 c7 3a e3 40 50 46 5d a5 70 99 08 00 45 00 .d.:.@PF ].p...E.
0010 00 43 9f 60 00 00 40 11 09 8f c0 a8 01 03 08 08 .C.`..@. ........
0020 08 08 8e 9e 00 35 00 2f 71 cf ef 49 01 20 00 01 .....5./ q..I. ..
0030 00 00 00 00 00 01 06 67 6f 6f 67 6c 65 03 63 6f .......g oogle.co
0040 6d 00 00 ff 00 01 00 00 29 10 00 00 00 00 00 00 m....... ).......
0050 00
dns python
:
0000 c8 64 c7 3a e3 40 50 46 5d a5 70 99 08 00 45 00 .d.:.@PF ].p...E.
0010 00 38 00 00 40 00 40 11 68 fa c0 a8 01 03 08 08 .8..@.@. h.......
0020 08 08 b8 62 00 35 00 24 23 6b 3d 31 01 00 00 01 ...b.5.$ #k=1....
0030 00 00 00 00 00 00 06 67 6f 6f 67 6c 65 03 63 6f .......g oogle.co
0040 6d 00 00 ff 00 01 m.....
For DNS query section:
dig
have AD bit: Set
flag:
002C-002D
: 01 20
for dig
and 01 00
for dns python
and this Additional records
section that except for dns-python
:
0046-0050
: 00 00 29 10 00 00 00 00 00 00 00
.
This actual also not only for google.com
also for logitech.com
mayby other.
So how can I make requests with dns python
as dig
with this additional section?
Source: (StackOverflow)