Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8444247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:21:28+00:00 2026-06-10T09:21:28+00:00

I’d like to write a script to pre-fetch a list of domain names for

  • 0

I’d like to write a script to pre-fetch a list of domain names for my caching dns server. I’m using the top 1,000,000 accessed websites from Alexa, available here:

http://s3.amazonaws.com/alexa-static/top-1m.csv.zip

How can I write a Python script to read this CSV file and perform an “nslookup” (or more efficient way) on each domain name listed, perhaps with a slight delay between each query? Or is there a better way to do this?

I’m guessing it would be most efficient to process the CSV line by line rather than read it all at once to minimize memory usage.

Specifically, I’m looking for a strategy for approaching this problem (libraries, tools, etc …). Sample code is appreciated, but not necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:21:29+00:00Added an answer on June 10, 2026 at 9:21 am

    You can totally stick with the python standard modules, as they offer everything you need.

    Since open returns a iterable file-object (without loading the whole file into memory), you could use code like this:

    from socket import gethostbyaddr 
    
    with open('top-1m.csv') as input:
        for line in input:
            index, host = line.strip().split(',')
            try: 
                output = gethostbyaddr(host)
                print "%s %s is %s/%s" % (index, host, output[0], output[2])
            except: 
                print host, "not found"
    

    Result:

    1 facebook.com is www-slb-10-08-prn1.facebook.com/[‘69.171.234.21’]
    2 google.com is fra07s07-in-f100.1e100.net/[‘209.85.148.100’]
    3 youtube.com is fra07s07-in-f93.1e100.net/[‘209.85.148.93’]
    4 yahoo.com is ir2.fp.vip.bf1.yahoo.com/[‘98.139.183.24’]
    baidu.com not found

    I would not recommend the csv here, since there are always just two values in each line. Use it if you need to handle things like quotecharacters or if you need to write a csv file and their like.

    While twisted is also a great module for networking, it would be a little overkill for such a simple task. Just use the socket module.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.