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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:16:03+00:00 2026-05-27T04:16:03+00:00

ok, this seems like it should be really simple but Im a bit confused:

  • 0

ok, this seems like it should be really simple but Im a bit confused:

i have two values – domain and ip
its best described with code:

        whois_result = Popen(['whois', str(domain)], stdout=PIPE,stderr=STDOUT).communicate()[0]
        debug_output(whois_result)
        if 'Not found' or 'No entries' in whois_result:
                print "Processing whois failure on '%s'" % str(domain)
                print "Trying the IP (%s) instead..." % ip
                whois_result = Popen(['whois', ip], stdout=PIPE,stderr=STDOUT).communicate()[0]
                debug_output(whois_result)
                if 'Not found' or 'No entries' in whois_result:
                        print "complete and utter whois failure, its you isnt it, not me."
                        return False
                else:
                        test = re.search("country.+([A-Z].)",whois_result)
                        countryid = test.group(1)

so this function checks the domain whois, if it doesnt find it, its tries a whois with the ip address, but what I want to know is what is the best way to check if the domain is equal to None dont bother with the domain check and go onto the ip check, yet also if the domain is NOT equal to None, do the domain check and then the ip check in that order. Sorry if this is basic, this has me a bit confused. I guess i could set a variable and test for that but is there a more elegant way of doing it ?

if i put at the top a

if domain != None:

the only way it seems i can do it is by repeating the code or setting a variable, I guess there must be other conditional tests I could use that I dont know about.

EDIT: update 2 based on answers below: – ive also put in the country checking code with my database.

def do_whois(data):
        if data is not None: return Popen(['whois', str(data)], stdout=PIPE,stderr=STDOUT).communicate()[0]
        return 'No entries'

def check_whois(data):
        conn = sqlite3.connect(db_name)
        cursor = conn.cursor()

        if 'No entries' in data or 'Not found' in data or 'No match for' in data:return False
        id = re.search("country.+([A-Z].)",data)
        if id is None:
                print "we didnt get nuttin from whois"
                return False
        countryid = id.group(1) 
        # fetch country from countrycode db
        cursor.execute("SELECT country,countrycode FROM countries WHERE countrycode = ?",(countryid,))
        country = cursor.fetchone()
        country = country[0]
        print "Server is from: " + country
        return (country,countryid)       

def find_country(domain, ip):
        return check_whois(do_whois(domain)) or check_whois(do_whois(ip))

part of the problem with making this robust is the varying values returned by the whois server eg for this IP: 67.222.137.216

the whois server returns :

@ : whois 67.222.137.216
#
# Query terms are ambiguous.  The query is assumed to be:
#     "n 67.222.137.216"
#
# Use "?" to get help.
#

#
# The following results may also be obtained via:
# http://whois.arin.net/rest/nets;q=67.222.137.216?showDetails=true&showARIN=false&ext=netref2
#

BLUESQUAREDATAVPSLLC BLUESQUAREDATAVPSLLCNET (NET-67-222-137-213-1) 67.222.137.213 - 67.222.137.244
DFW Datacenter DFW-DATACENTER (NET-67-222-128-0-1) 67.222.128.0 - 67.222.159.255


#
# ARIN WHOIS data and services are subject to the Terms of Use
# available at: https://www.arin.net/whois_tou.html
#

thanks for any help.

  • 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-05-27T04:16:04+00:00Added an answer on May 27, 2026 at 4:16 am

    Try this

    def do_whois(data):
        if data: return Popen(['whois', str(data)], stdout=PIPE,stderr=STDOUT).communicate()[0]
        return 'No entries'
    
    def check_whois(data):
        if 'No entries' in data or 'Not found' in data:return False
        test = re.search("country.+([A-Z].)",whois_result)
        return test.group(1)
    
    def find_whois(domain, ip):
        return check_whois(do_whois(domain)) or check_whois(do_whois(ip))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like it should be really simple, but I'm unable to figure this
I have what seems like it should be a really simple problem, but somehow
This seems like it should be pretty straight forward, but I'm apparently confused. I
Really simple question: Am I missing something? Seems like this should be all that
This seems like it should be really simple. I compiled a library in Qt
This seems like a really simple question but I haven't seen it answered anywhere.
This seems like it should be obvious but I can't figure it out. Suppose
This seems like it should be something very easy to do, but every time
This seems like it should be an easy thing to do, but for the
It seems like this should be straightforward but I'm boggling. I've got my listview

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.