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 8315593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T21:10:01+00:00 2026-06-08T21:10:01+00:00

I am trying to come up with a script to check if a domain

  • 0

I am trying to come up with a script to check if a domain name resolves to its IP address via dns; using a python script I wrote.

I want to be able to do this in a few sequential loops, however after trying to run a loop once, the second time i run the script, the names that previously returned a successful dns resolution response, now do not.

Below is my script:

#! C:\Python27
import socket,time

localtime = time.asctime( time.localtime(time.time()) )


def hostres(hostname):
    print "Attempting to resolve " + hostname 
    try:
        socket.gethostbyname(hostname)
        print "Resolved Successfully!"
    except socket.error:
        print "Could Not Resolve"

print "*************************************************"
print "Website loop starting.."
print "Local current time :", localtime
print "*************************************************"
print ""

text_file = open("sites.txt", "r")
lines = text_file.readlines()
for line in lines:
    hostres(line)
text_file.close()

The contents of the text file are:

www.google.com
en.wikipedia.org
www.youtube.com
us.gamespot.com

I am thinking it is to do with these domains servers recognizing the script as a “bot” rather than a legitimate end-user, would it be correct to assume this?

If so, how can I still check if the dns name resolves by looking up the name of the website (or IP, does not matter) and be able to run this without getting a false reading of “request failed” despite the fact that the service is fully accessible from a browser?

  • 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-08T21:10:03+00:00Added an answer on June 8, 2026 at 9:10 pm

    Several problems in this question.

    1. You are not checking if “a website responds” you are testing DNS resolution. All your DNS requests go to a single name server, your LDNS resolver. If all of them resolve, it still says nothing about the status of the website. Also, since you aren’t actually talking to these website, they have no way of knowing you’re a bot. They can only detect this (based on the HTTP user-agent header) if you make a HTTP request.
    2. Regarding your code problem, you need to trim the newline character before you can do a socket.gethostbyname() on it. Replace socket.gethostbyname(hostname) with socket.gethostbyname(hostname.rstrip()) and you’ll be fine.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to come up with a powershell script thatcan determine the last number
I am trying to come up with a solution that doesn't involve using other
I am trying out some CGI-scripting in Python. If a request come to my
In trying to build a ant script for my Flex project i've come across
Noob help please. I'm trying to write a script that will check if a
I come from more of a Python and CTYPES background...and am trying to work
I'm trying to learn PHP using NetBeans although I've come up against a problem
I'm trying add some shell extensions using python with icons and a sub menu
im trying to come up with a design for a wrapper for use when
I'm trying to come up with an algorithm that will do the following: If

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.