how to extract just the IP address from a DNS query

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:



lab-1:/var/# dig +answer smtp.mydomain.net +short 
smtp.ggs.mydomain.net
10.11.11.11


I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.



Thanks.







share|improve this question
















  • 4




    drop +answer use just +short
    – man0v
    Feb 26 at 14:16










  • that doesn't work. still gives me the same results @man0v
    – dot
    Feb 26 at 14:18










  • weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
    – man0v
    Feb 26 at 14:19






  • 1




    @dot post dig version too. Use dig -v
    – Patrick
    Feb 26 at 14:26






  • 1




    Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
    – ctx
    Feb 26 at 14:31














up vote
0
down vote

favorite












I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:



lab-1:/var/# dig +answer smtp.mydomain.net +short 
smtp.ggs.mydomain.net
10.11.11.11


I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.



Thanks.







share|improve this question
















  • 4




    drop +answer use just +short
    – man0v
    Feb 26 at 14:16










  • that doesn't work. still gives me the same results @man0v
    – dot
    Feb 26 at 14:18










  • weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
    – man0v
    Feb 26 at 14:19






  • 1




    @dot post dig version too. Use dig -v
    – Patrick
    Feb 26 at 14:26






  • 1




    Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
    – ctx
    Feb 26 at 14:31












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:



lab-1:/var/# dig +answer smtp.mydomain.net +short 
smtp.ggs.mydomain.net
10.11.11.11


I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.



Thanks.







share|improve this question












I'd like to know how to extract just the IP address from a DNS / dig query. The query I'm running looks like this:



lab-1:/var/# dig +answer smtp.mydomain.net +short 
smtp.ggs.mydomain.net
10.11.11.11


I'd like to be able to get just the IP address returned.
I'm currently playing around with the bash pipe and the awk command. But so far, nothing I've tried is working.



Thanks.









share|improve this question











share|improve this question




share|improve this question










asked Feb 26 at 14:14









dot

2531310




2531310







  • 4




    drop +answer use just +short
    – man0v
    Feb 26 at 14:16










  • that doesn't work. still gives me the same results @man0v
    – dot
    Feb 26 at 14:18










  • weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
    – man0v
    Feb 26 at 14:19






  • 1




    @dot post dig version too. Use dig -v
    – Patrick
    Feb 26 at 14:26






  • 1




    Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
    – ctx
    Feb 26 at 14:31












  • 4




    drop +answer use just +short
    – man0v
    Feb 26 at 14:16










  • that doesn't work. still gives me the same results @man0v
    – dot
    Feb 26 at 14:18










  • weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
    – man0v
    Feb 26 at 14:19






  • 1




    @dot post dig version too. Use dig -v
    – Patrick
    Feb 26 at 14:26






  • 1




    Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
    – ctx
    Feb 26 at 14:31







4




4




drop +answer use just +short
– man0v
Feb 26 at 14:16




drop +answer use just +short
– man0v
Feb 26 at 14:16












that doesn't work. still gives me the same results @man0v
– dot
Feb 26 at 14:18




that doesn't work. still gives me the same results @man0v
– dot
Feb 26 at 14:18












weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
– man0v
Feb 26 at 14:19




weird, it works for me on centos.. wonder what version of dig you are using? What distro(or os)?
– man0v
Feb 26 at 14:19




1




1




@dot post dig version too. Use dig -v
– Patrick
Feb 26 at 14:26




@dot post dig version too. Use dig -v
– Patrick
Feb 26 at 14:26




1




1




Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
– ctx
Feb 26 at 14:31




Is smtp.mydomain.net an alias for smtp.ggs.mydomain.net?
– ctx
Feb 26 at 14:31










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










I believe dig +short outputs two lines for you because the domain
you query, smtp.mydomain.net is a CNAME for smtp.ggs.mydomain.net,
and dig prints the intermediate resolution step.



You can probably rely on the last line from dig's output being the IP
you want, though, and therefore the following should do:



dig +short smtp.mydomain.net | tail -n1





share|improve this answer



























    up vote
    1
    down vote













    @dhag's answer sounds good; if you do not want to “rely on the last line from dig's output being the IP” you can use grep to extract just the numerical IP address:



    dig +short smtp.mydomain.net | grep '^[.0-9]*$'





    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "106"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );








       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426693%2fhow-to-extract-just-the-ip-address-from-a-dns-query%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      I believe dig +short outputs two lines for you because the domain
      you query, smtp.mydomain.net is a CNAME for smtp.ggs.mydomain.net,
      and dig prints the intermediate resolution step.



      You can probably rely on the last line from dig's output being the IP
      you want, though, and therefore the following should do:



      dig +short smtp.mydomain.net | tail -n1





      share|improve this answer
























        up vote
        1
        down vote



        accepted










        I believe dig +short outputs two lines for you because the domain
        you query, smtp.mydomain.net is a CNAME for smtp.ggs.mydomain.net,
        and dig prints the intermediate resolution step.



        You can probably rely on the last line from dig's output being the IP
        you want, though, and therefore the following should do:



        dig +short smtp.mydomain.net | tail -n1





        share|improve this answer






















          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          I believe dig +short outputs two lines for you because the domain
          you query, smtp.mydomain.net is a CNAME for smtp.ggs.mydomain.net,
          and dig prints the intermediate resolution step.



          You can probably rely on the last line from dig's output being the IP
          you want, though, and therefore the following should do:



          dig +short smtp.mydomain.net | tail -n1





          share|improve this answer












          I believe dig +short outputs two lines for you because the domain
          you query, smtp.mydomain.net is a CNAME for smtp.ggs.mydomain.net,
          and dig prints the intermediate resolution step.



          You can probably rely on the last line from dig's output being the IP
          you want, though, and therefore the following should do:



          dig +short smtp.mydomain.net | tail -n1






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 26 at 14:38









          dhag

          10.7k32642




          10.7k32642






















              up vote
              1
              down vote













              @dhag's answer sounds good; if you do not want to “rely on the last line from dig's output being the IP” you can use grep to extract just the numerical IP address:



              dig +short smtp.mydomain.net | grep '^[.0-9]*$'





              share|improve this answer
























                up vote
                1
                down vote













                @dhag's answer sounds good; if you do not want to “rely on the last line from dig's output being the IP” you can use grep to extract just the numerical IP address:



                dig +short smtp.mydomain.net | grep '^[.0-9]*$'





                share|improve this answer






















                  up vote
                  1
                  down vote










                  up vote
                  1
                  down vote









                  @dhag's answer sounds good; if you do not want to “rely on the last line from dig's output being the IP” you can use grep to extract just the numerical IP address:



                  dig +short smtp.mydomain.net | grep '^[.0-9]*$'





                  share|improve this answer












                  @dhag's answer sounds good; if you do not want to “rely on the last line from dig's output being the IP” you can use grep to extract just the numerical IP address:



                  dig +short smtp.mydomain.net | grep '^[.0-9]*$'






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 26 at 16:16









                  Renardo

                  862




                  862






















                       

                      draft saved


                      draft discarded


























                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426693%2fhow-to-extract-just-the-ip-address-from-a-dns-query%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Popular posts from this blog

                      How to check contact read email or not when send email to Individual?

                      Displaying single band from multi-band raster using QGIS

                      How many registers does an x86_64 CPU actually have?