Quantcast
Channel: linuxadmin: Expanding Linux SysAdmin knowledge
Viewing all articles
Browse latest Browse all 17761

Dig command help

$
0
0

Hey guys,

Im trying to use dig in a script to return only the A record and currently its not working for me the way i thought it was meant to and i was hoping someone could help me understand why, and maybe point me in the right direction.

The script section im looking at is this line;

subprocess.Popen(['dig',row[0],'+short','A'], shell=False, stdout=subprocess.PIPE) 

what i want to return is "1.1.1.1" or whatever IP the A record is pointing too

It wasnt working so on command line i ran the dig commands on their own;

dig testhostname.info +short A dig testhostname.info +short dig +short testhostname.info 

and all return this output:

CNAME1(eg google1.com) CNAME2(eg google2.com) 1.1.1.1 

im not sure why its displaying the CNAME as im specifying the A record... after some googling i found this command that somewhat fixes the issue;

dig A testhostname.info +short | cut -d' ' -f2 | sed '1q;d' | xargs dig +short 

which leaves out the first CNAME and only displays the second CNAME and the A record;

CNAME2(eg google2.com) 1.1.1.1 

but im not sure what in the last command is helping me and i dont know if theres a better way to use the dig command..

submitted by Tech_Adam
[link][11 comments]

Viewing all articles
Browse latest Browse all 17761

Trending Articles