Look Up IPs From Text File, Generate Another Text File With Specific FormattingRetrieve IPv6 address of...

Why is gun control associated with the socially liberal Democratic party?

Why not make one big CPU core?

Interview was just a one hour panel. Got an offer the next day; do I accept or is this a red flag?

Does WiFi affect the quality of images downloaded from the internet?

My players want to use called-shots on Strahd

What is the color associated with lukewarm?

Fastest path on a snakes and ladders board

Arcane Tradition and Cost Efficiency: Learn spells on level-up, or learn them from scrolls/spellbooks?

My parents claim they cannot pay for my college education; what are my options?

How to address players struggling with simple controls?

What things do I only get a limited opportunity to take photos of?

100-doors puzzle

Is there a risk to write an invitation letter for a stranger to obtain a Czech (Schengen) visa?

Dedicated bike GPS computer over smartphone

Can an open source licence be revoked if it violates employer's IP?

Manager wants to hire me; HR does not. How to proceed?

Threading data on TimeSeries

Boss making me feel guilty for leaving the company at the end of my internship

What did the 8086 (and 8088) do upon encountering an illegal instruction?

Co-worker is now managing my team. Does this mean that I'm being demoted?

...and then she held the gun

Leveling up and Getting Items!

Is fission/fusion to iron the most efficient way to convert mass to energy?

Jam with honey & without pectin has a saucy consistency always



Look Up IPs From Text File, Generate Another Text File With Specific Formatting


Retrieve IPv6 address of website using terminalWhy does nslookup fail for DNS records set to a private address?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















I'd like a way of looking up all the domains in a text file (one domain per line) and generating another text file with the output as the IP address, a space, the domain name, a space and then the domain name with www. prepending it.



For example, if the source text file contains two lines:



1.gravatar.com
abcya.com


the new text file would contain 3 lines as 1.gravatar.com has both an IPv4 and an IPv6 address:



72.21.91.121 1.gravatar.com www.1.gravatar.com
2a04:fa87:fffe::c000:4902 1.gravatar.com www.1.gravatar.com
104.198.14.52 abcya.com www.abcya.com


I'm running a Ubuntu derivative and can use nslookup to get the IPv4 and IPv6 addresses. However, the source text file is a list of over 2,000 domains - so doing it by hand would take a very long time with plenty of room for error.



And if the answer could allow for no IP address too. If the domain no longer exists (as in the case of alwaysbeready.mybigcommerce.com), nslookup returns
** server can't find alwaysbeready.mybigcommerce.com: NXDOMAIN
So, maybe have NXDOMAIN in place of the IP Address in the resulting text file?



Thanks in advance to anyone who can help.










share|improve this question































    0















    I'd like a way of looking up all the domains in a text file (one domain per line) and generating another text file with the output as the IP address, a space, the domain name, a space and then the domain name with www. prepending it.



    For example, if the source text file contains two lines:



    1.gravatar.com
    abcya.com


    the new text file would contain 3 lines as 1.gravatar.com has both an IPv4 and an IPv6 address:



    72.21.91.121 1.gravatar.com www.1.gravatar.com
    2a04:fa87:fffe::c000:4902 1.gravatar.com www.1.gravatar.com
    104.198.14.52 abcya.com www.abcya.com


    I'm running a Ubuntu derivative and can use nslookup to get the IPv4 and IPv6 addresses. However, the source text file is a list of over 2,000 domains - so doing it by hand would take a very long time with plenty of room for error.



    And if the answer could allow for no IP address too. If the domain no longer exists (as in the case of alwaysbeready.mybigcommerce.com), nslookup returns
    ** server can't find alwaysbeready.mybigcommerce.com: NXDOMAIN
    So, maybe have NXDOMAIN in place of the IP Address in the resulting text file?



    Thanks in advance to anyone who can help.










    share|improve this question



























      0












      0








      0








      I'd like a way of looking up all the domains in a text file (one domain per line) and generating another text file with the output as the IP address, a space, the domain name, a space and then the domain name with www. prepending it.



      For example, if the source text file contains two lines:



      1.gravatar.com
      abcya.com


      the new text file would contain 3 lines as 1.gravatar.com has both an IPv4 and an IPv6 address:



      72.21.91.121 1.gravatar.com www.1.gravatar.com
      2a04:fa87:fffe::c000:4902 1.gravatar.com www.1.gravatar.com
      104.198.14.52 abcya.com www.abcya.com


      I'm running a Ubuntu derivative and can use nslookup to get the IPv4 and IPv6 addresses. However, the source text file is a list of over 2,000 domains - so doing it by hand would take a very long time with plenty of room for error.



      And if the answer could allow for no IP address too. If the domain no longer exists (as in the case of alwaysbeready.mybigcommerce.com), nslookup returns
      ** server can't find alwaysbeready.mybigcommerce.com: NXDOMAIN
      So, maybe have NXDOMAIN in place of the IP Address in the resulting text file?



      Thanks in advance to anyone who can help.










      share|improve this question
















      I'd like a way of looking up all the domains in a text file (one domain per line) and generating another text file with the output as the IP address, a space, the domain name, a space and then the domain name with www. prepending it.



      For example, if the source text file contains two lines:



      1.gravatar.com
      abcya.com


      the new text file would contain 3 lines as 1.gravatar.com has both an IPv4 and an IPv6 address:



      72.21.91.121 1.gravatar.com www.1.gravatar.com
      2a04:fa87:fffe::c000:4902 1.gravatar.com www.1.gravatar.com
      104.198.14.52 abcya.com www.abcya.com


      I'm running a Ubuntu derivative and can use nslookup to get the IPv4 and IPv6 addresses. However, the source text file is a list of over 2,000 domains - so doing it by hand would take a very long time with plenty of room for error.



      And if the answer could allow for no IP address too. If the domain no longer exists (as in the case of alwaysbeready.mybigcommerce.com), nslookup returns
      ** server can't find alwaysbeready.mybigcommerce.com: NXDOMAIN
      So, maybe have NXDOMAIN in place of the IP Address in the resulting text file?



      Thanks in advance to anyone who can help.







      nslookup






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 22 mins ago







      Eric Bradshaw

















      asked 1 hour ago









      Eric BradshawEric Bradshaw

      133




      133






















          1 Answer
          1






          active

          oldest

          votes


















          0














          A python solution



          #!/usr/bin/python3

          import socket
          #this module is core networking module in Python,
          #can be used to resolve domain names.

          sourcefile = 'sourcefile.txt' #file with domain names
          outfile = 'results.txt' #file to write the IP addresses

          with open(sourcefile, 'r') as inputf:
          #This opens the sourcefile in read mode to see what are the domains
          with open(outfile, 'a') as outputf:
          #This opens the outfile in append mode to write the results
          domains = inputf.readlines()
          #This reads all the domains in sourcefile line by line
          for domain in domains:
          #This for loop will go one by one on domains.
          domain = domain.strip("n")
          #as the every domain in the file are in newline,
          #the socket function will have trouble, so strip off the newline char
          outputf.write(socket.gethostbyname("www."+domain)+" "+domain+ " www."+domain+"n")
          #write function will write the ip and domain to the outputf file we opened.
          #gethostbyname will resolve the domain




          share
























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f524792%2flook-up-ips-from-text-file-generate-another-text-file-with-specific-formatting%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            A python solution



            #!/usr/bin/python3

            import socket
            #this module is core networking module in Python,
            #can be used to resolve domain names.

            sourcefile = 'sourcefile.txt' #file with domain names
            outfile = 'results.txt' #file to write the IP addresses

            with open(sourcefile, 'r') as inputf:
            #This opens the sourcefile in read mode to see what are the domains
            with open(outfile, 'a') as outputf:
            #This opens the outfile in append mode to write the results
            domains = inputf.readlines()
            #This reads all the domains in sourcefile line by line
            for domain in domains:
            #This for loop will go one by one on domains.
            domain = domain.strip("n")
            #as the every domain in the file are in newline,
            #the socket function will have trouble, so strip off the newline char
            outputf.write(socket.gethostbyname("www."+domain)+" "+domain+ " www."+domain+"n")
            #write function will write the ip and domain to the outputf file we opened.
            #gethostbyname will resolve the domain




            share




























              0














              A python solution



              #!/usr/bin/python3

              import socket
              #this module is core networking module in Python,
              #can be used to resolve domain names.

              sourcefile = 'sourcefile.txt' #file with domain names
              outfile = 'results.txt' #file to write the IP addresses

              with open(sourcefile, 'r') as inputf:
              #This opens the sourcefile in read mode to see what are the domains
              with open(outfile, 'a') as outputf:
              #This opens the outfile in append mode to write the results
              domains = inputf.readlines()
              #This reads all the domains in sourcefile line by line
              for domain in domains:
              #This for loop will go one by one on domains.
              domain = domain.strip("n")
              #as the every domain in the file are in newline,
              #the socket function will have trouble, so strip off the newline char
              outputf.write(socket.gethostbyname("www."+domain)+" "+domain+ " www."+domain+"n")
              #write function will write the ip and domain to the outputf file we opened.
              #gethostbyname will resolve the domain




              share


























                0












                0








                0







                A python solution



                #!/usr/bin/python3

                import socket
                #this module is core networking module in Python,
                #can be used to resolve domain names.

                sourcefile = 'sourcefile.txt' #file with domain names
                outfile = 'results.txt' #file to write the IP addresses

                with open(sourcefile, 'r') as inputf:
                #This opens the sourcefile in read mode to see what are the domains
                with open(outfile, 'a') as outputf:
                #This opens the outfile in append mode to write the results
                domains = inputf.readlines()
                #This reads all the domains in sourcefile line by line
                for domain in domains:
                #This for loop will go one by one on domains.
                domain = domain.strip("n")
                #as the every domain in the file are in newline,
                #the socket function will have trouble, so strip off the newline char
                outputf.write(socket.gethostbyname("www."+domain)+" "+domain+ " www."+domain+"n")
                #write function will write the ip and domain to the outputf file we opened.
                #gethostbyname will resolve the domain




                share













                A python solution



                #!/usr/bin/python3

                import socket
                #this module is core networking module in Python,
                #can be used to resolve domain names.

                sourcefile = 'sourcefile.txt' #file with domain names
                outfile = 'results.txt' #file to write the IP addresses

                with open(sourcefile, 'r') as inputf:
                #This opens the sourcefile in read mode to see what are the domains
                with open(outfile, 'a') as outputf:
                #This opens the outfile in append mode to write the results
                domains = inputf.readlines()
                #This reads all the domains in sourcefile line by line
                for domain in domains:
                #This for loop will go one by one on domains.
                domain = domain.strip("n")
                #as the every domain in the file are in newline,
                #the socket function will have trouble, so strip off the newline char
                outputf.write(socket.gethostbyname("www."+domain)+" "+domain+ " www."+domain+"n")
                #write function will write the ip and domain to the outputf file we opened.
                #gethostbyname will resolve the domain





                share











                share


                share










                answered 1 min ago









                Vignesh SPVignesh SP

                52




                52






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f524792%2flook-up-ips-from-text-file-generate-another-text-file-with-specific-formatting%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Hudson River Historic District Contents Geography History The district today Aesthetics Cultural...

                    The number designs the writing. Feandra Aversely Definition: The act of ingrafting a sprig or shoot of one...

                    How big is the pipe buffer?Turn off buffering in pipeIn what order do piped commands run?When would you use...