Example #1
0
def main(url):

    status = []

    hostname = getHostname(url)
    response = getResponse(url)

    if not response:
        exit()
    # with open('markup.txt', 'r') as file:
    #     soup_string = file.read()
    soup_string = response.read()
    soup = BeautifulSoup(soup_string, 'html.parser')

##1st feature added
    status.append(having_ip_address(url))
##2nd feature added
    status.append(url_length(url))
##3rd feature added
    status.append(shortening_service(url))
    # print(shortening_service_redirect(response))

##4th feature added
    status.append(shortening_service_redirect(response))

##5th feature  added
    dns = 1
    try:
        domain = whois.query(hostname)
    except:
        dns = -1

    if dns == -1:
        status.append(-1)
    else:
        status.append(domain_registry_expiration(whois.query(hostname)))

##6th feature added
    status.append(double_slash_redirecting(url))
##7th feature added
    status.append(crossdomain_req_url(url, soup, hostname))
##8th feature added
    status.append(https_token(url))
##9th feature added
    status.append(links_in_anchor(url,soup,hostname))
##10th feature added
    status.append(links_in_tags(url,soup,hostname))
##11th feature added
    status.append(sfh(url,soup,hostname))
##12th feature added
    status.append(mail_redirection(soup))
##13th feature added
    if dns == -1:
        status.append(-1)
    else:
        status.append(abnormal_url(domain, url))
Example #2
0
 def is_available(self, domain):
     '''
     Returns True if the domain is unregistered, False otherwise.
     '''
     result = False
     try:
         whois.query(domain)
     except Exception:
         result = True
     if result is True:
         with open('log.out', 'a') as f:
             f.write('%s\n' % domain)
     return result
Example #3
0
def get_features(url, label):
    result = []
    url = str(url)
    result.append(url)
    # url = "http://royalmail.reschedule-missed-parcel.com/"
    ext = tldextract.extract(url)
    domain = '.'.join(ext[1:])

    try:
        whois.query(domain)
    except:
        result.append('-1')
        result.append(str(label))
        return result
    else:
        w = whois.query(domain)

    if w is None:
        return result

    avg_month_time = 365.2425 / 12.0

    #calculate creation age in months

    create_date = -1
    if w.creation_date == None or type(w.creation_date) is str:
        create_date = -1
    else:
        if (type(w.creation_date) is list):
            create_date = w.creation_date[-1]
        else:
            create_date = w.creation_date

    #calculate expiry age in months

    expiry_date = -1
    if (w.expiration_date == None or type(w.expiration_date) is str):
        expiry_date = -1
    else:
        if (type(w.expiration_date) is list):
            expiry_date = w.expiration_date[-1]
        else:
            expiry_date = w.expiration_date

    if create_date == -1 or expiry_date == -1:
        result.append('-1')
    else:
        duration = round(((expiry_date - create_date).days) / avg_month_time)
        result.append(str(duration))
    result.append(str(label))
    return result
Example #4
0
    def domain_get_status(self, domain):
        domain_name = tldextract.extract(domain)
        domain = domain_name.registered_domain
        domain = whois.query(domain)

        logging.debug('Domain check result ' + str(domain.__dict__))

        expire_in = domain.expiration_date.replace(
            tzinfo=None) - datetime.utcnow().replace(tzinfo=None)
        days_to_expire = 0
        if expire_in.days > 0:
            days_to_expire = expire_in.days

        data = {
            'domain_name':
            domain.name,
            'registrar':
            domain.registrar,
            'creation_date':
            domain.creation_date.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
            'expiration_date':
            domain.expiration_date.strftime("%Y-%m-%dT%H:%M:%S.000Z"),
            'days_to_expire':
            days_to_expire,
        }
        logging.debug('Return data:' + str(data))
        return data
Example #5
0
def whoami(target, post):
    #target=input("Enter the IP Address/Domain:")
    getweb = str(ping(target))
    ip = re.compile(
        '(([2][5][0-5]\.)|([2][0-4][0-9]\.)|([0-1]?[0-9]?[0-9]\.)){3}' +
        '(([2][5][0-5])|([2][0-4][0-9])|([0-1]?[0-9]?[0-9]))')
    match = ip.search(getweb)
    if match:
        # target=match.group()
        w = whois.query(target).__dict__
        print("Domain Name:" + str(w['name']))
        if w['registrar']:
            print("Register:" + str(w['registrar']))

        try:
            print("Whois Server:" + str(w['whois_server']))
        except Exception as e:
            print(e)

        print("Server:" + str(w['name_servers']))
        print("Emails:" + str(w['emails']))
        try:
            print("Organisation:" + str(w['org']))
        except Exception as e:
            print("Organisation:" + str(w['organization']))
            print(e)
        try:
            print("Address:" + str(w['address']))
            print("City:" + str(w['city']))
            print("State:" + str(w['state']))
            print("Zipcode:" + str(w['zipcode']))
        except Exception as e:
            print(e)
        print("Country:" + str(w['country']))
Example #6
0
def get_whois_data(indicator):
    data = {
        'whois_creationdate': 'n/a',
        'whois_registrar': 'n/a',
        'whois_expirationdate': 'n/a',
        'whois_nameservers': 'n/a',
        'whois_lastupdated': 'n/a'
    }

    try:
        domain_details = whois.query(indicator)
        result = domain_details.__dict__
        try:
            data['whois_creationdate'] = result.get('creation_date',
                                                    {}).strftime("%m/%d/%Y")
        except:
            data['whois_creationdate'] = "Unknown"
        try:
            data['whois_expiration_date'] = result.get('expiration_date',
                                                       {}).strftime("%m/%d/%Y")
        except:
            data['whois_expiration_date'] = "Unknown"
        try:
            data['whois_last_updated'] = result.get('last_updated',
                                                    {}).strftime("%m/%d/%Y")
        except:
            data['whois_last_updated'] = "Unknown"
        data['name_servers'] = str(result.get('name_servers', {}))
    except Exception as err:
        print('Whois error on indicator {} : {}'.format(
            indicator,
            traceback.format_exception(type(err), err, err.__traceback__)))

    return data
    def run(self, params={}):
        domain = str(
            params.get(Input.DOMAIN)
        )  # Comes in as unicode - whois library has assert for type on str
        self.logger.info("Getting whois information for %s" % domain)

        if not self.is_valid_domain(domain=domain):
            raise PluginException(
                cause="Invalid domain as input.",
                assistance="Ensure the domain is not prefixed with a protocol."
            )

        try:
            lookup_results = whois.query(
                domain,
                ignore_returncode=1)  # ignore_returncode required for plugin
        except Exception as e:
            self.logger.error("Error occurred: %s" % e)
            raise
        else:
            serializable_results = lookup_results.get_json_serializable()
            serializable_results = insightconnect_plugin_runtime.helper.clean_dict(
                serializable_results)

            return serializable_results
Example #8
0
    def post(self):
        headers = request.headers
        secret_key = common.secret_key()
        request_key = headers.get("X-Whois-Key")
        domain = request.data.decode()

        if secret_key is None:
            return response(400, message="secret key not found")

        if common.validate_domain(domain) is not True:
            return response(403, message="domain not supported")

        if request_key == secret_key:
            whois_data = whois.query(domain)
            data = {
                "name": whois_data.name,
                "registrar": whois_data.registrar,
                "creation_date": str(whois_data.creation_date),
                "expiration_date": str(whois_data.expiration_date),
                "last_updated": str(whois_data.last_updated),
                "name_servers": list(whois_data.name_servers),
            }
            return response(200, data=data)
        else:
            return response(401)
Example #9
0
def lobby1():
    a = open("Banner/ipbanner.txt", "r")
    asciiii = "".join(a.readlines())
    print(colorText(asciiii))
    hub1 = input(
        colorText(
            "[[cyan]][ 1 ] Expiration / Create date (Domain) \n[ 2 ] Domain alive ? \n[ 3 ] Ping an IP / Domain (ms) \n[ 4 ] What is my ip adress ?  \n[ 5 ] Back \n\n[ ? ] Choice : "
        ))
    try:
        val1 = int(hub1)
    except ValueError:
        print(
            colorText("\n[[red]][-] Error, choose an option between 1 and 4"))
        lobby()
    if val1 >= 6:
        print(
            colorText("\n[[red]][-] Error, choose an option between 1 and 4"))
        lobby1()
    if val1 == 1:
        target = input("Website domain (ex google.com) : ")
        if 'https' in target:
            print(
                colorText(
                    '[[red]]\n[-] Wrong format ! (Correct format : xxxxx.fr'))
            lobby1()
        elif 'http' in target:
            print(
                colorText(
                    '[[red]]\n[-] Wrong format ! (Correct format : xxxxx.fr'))
            lobby1()
        elif '/' in target:
            print(
                colorText(
                    '[[red]]\n[-] Wrong format ! (Correct format : xxxxx.fr'))
            lobby1()
        domain = whois.query(target)
        print(colorText("[[green]][+] Domain expire date :"),
              domain.expiration_date)
        print(colorText("[[green]][+] Domain creation date :"),
              domain.creation_date)
        lobby1()
    if val1 == 2:
        target = input("Website domain (ex google.com) : ")
        response = os.system("ping -c 1 -w2 " + target + " > /dev/null 2>&1")
        if response == 0:
            print(colorText("\n[[green]][+] Website Up !\n "))
            lobby1()
        else:
            print(colorText("[[red]][-] Website down :( "))
            lobby1()
    if val1 == 3:
        ip = str(input("\nIp adress or domain (ex google.com) : "))
        print("\n")
        commande = ("ping -c 5 {}").format(ip)
        os.system(commande)
        lobby1()
    if val1 == 4:
        userip()
    if val1 == 5:
        lobby()
def db_insert(host):
    with sqlite3.connect('whois.db') as connect:
        connect.execute('''create table if not exists websites 
            (id INTEGER primary key autoincrement, domain char(100) unique, 
            registrar char(150), expiration_date timestamp, creation_date timestamp, last_updated timestamp)'''
                        )
        try:
            domain = whois.query(host)
        except whois.exceptions.WhoisCommandFailed:
            return
        except:
            return
        try:
            connect.execute(
                '''
                insert into websites (domain, registrar, expiration_date, creation_date, last_updated)
                values(?,?,?,?,?)
            ''', (domain.name, domain.registrar, domain.expiration_date,
                  domain.creation_date, domain.last_updated))
            connect.commit()
        except sqlite3.IntegrityError:
            print('ignore this exception')
        except Exception as e:
            print('error occured in database funcition')
            print('v' * 10)
            print('\n' * 4)
            print(e)
            print('^' * 10)
def getRegistrar(hostName):
    try:
        addrdomain = whois.query(hostName)
        reg = addrdomain.registrar
        return reg
    except:
       return "lookup failed"
Example #12
0
def domain_features(url):
    out = [1, 1, 1]
    try:
        q = whois.query(getDomain(url))
        if q is not None:
            out[0] = -1
            today = datetime.datetime.now()
            creation_date = q.creation_date
            if creation_date is None:
                out[1] = 1
            else:
                age = (today - creation_date).days * 1. / 365
                if (age <= 0.5):
                    out[1] = 1
                else:
                    out[1] = -1
            expiration_date = q.expiration_date
            if expiration_date is None:
                out[2] = 1
            else:
                lifetime = (expiration_date - today).days * 1. / 365
                if (lifetime <= 1):
                    out[2] = 1
                else:
                    out[2] = -1
        else:
            out = [1, 1, 1]
    except:
        out = [1, 1, 1]

    return out
Example #13
0
def look_up(names, use_cache=True):
    """
    Uses whois to find out whether the domain name is available.

    Later, should also figure out how many search results there are.
    """
    global _all_names_whois
    if use_cache and os.path.exists(_all_names_whois_cache_filename):
        with open(_all_names_whois_cache_filename, 'rb') as f:
            _all_names_whois = pickle.load(f)
    else:
        print
        for i, name in enumerate(names):
            if name.get_popularity(normalized=True) < 0.0001:
                continue
            print "\r%05d / %05d - testing whois for %20swinter.com"%(
                i, len(names), name.name.lower()),
            try:
                result = whois.query(name.name.lower() + 'winter.com')
            except (KeyboardInterrupt, SystemExit), e:
                print "\nStopping whois lookups due to KeyboardInterrupt."
                break
            except Exception, e:
                print "\nCouldn't fetch %s: %s"%(name.name.lower() + 'winter.com', e)
                _all_names_whois[name.name] = False
                continue
            _all_names_whois[name.name] = bool(result)
            print bool(result),
            if result:
                print
Example #14
0
def main():
    # Бесконечный цикл
    while True:
        # Генерируем домен
        query_name = (generator(Settings.domain_level, Settings.domain_symbols))
        # Проверяем наличие домена в DNS
        ar = AsyncResolver([query_name+Settings.domain_zone])
        resolved = ar.resolve()
        # Цикл для проверки есть ли ip у домена
        for host, ip in resolved.items():
            # Ловим выход из скрипта
            signal.signal(signal.SIGINT, signal_handler)
            # Если ip нету в DNS то проверяем домен через WHOIS, сразу через WHOIS проверять нельзя
            # Так как это долго и они банят
            if ip is None:
                # Выводим информацию что ip нету в DNS
                print("\033[92m%s could not be resolved.\033[0m" % (host))
                # Обращаемся в WHOIS, если домен занят - выводим дату до которой
                # он зарегистрирован, если свободен то пишем это и записываем
                # домен в файл
                try:
                    domain = whois.query(host)
                    print(domain.expiration_date)
                except Exception:
                    print("\033[95mFREE " + host + "\033[0m")
                    Settings.domainsFoundFile.write(host + '\n')
                time.sleep(2)
Example #15
0
 def getWhoIs(self, dom):
     """
 Return a dictionary of whois infomation
 Will throw exception if tld server not known, or query limit reached
 """
     ws = whois.query(dom)
     return ws.__dict__
Example #16
0
def query_whois_internet(question):
	global rate_limit_timestamp
	global rate_limit_use_backlog
	global backlog_questions
	my_rate = rate_limit_timestamp + datetime.timedelta(seconds=rate_limit_queries)
	if threading.currentThread().getName() == 'backlog_worker':
		my_rate = datetime.datetime.now()
	## This function performs a whois query to the internet, caching results
	if only_use_cache == True:
		results = not_cached_result
		return results
	elif my_rate > datetime.datetime.now() :
		logger("ratelimit - - exceeded configured request interval: " + str(question))
		stats['exceeded_rate_limit']+=1
		if rate_limit_use_backlog == True:
			logger("ratelimit - - adding question to backlog: " + str(question))
			backlog_questions.append(question)
		return None
	else:
                try:
                    if "whois" in dir(whois):
                        lookup_results = whois.whois(question)
                    elif "query" in dir(whois):
                        lookup)results = whois.query(question).__dict__
	        except Exception as e:
			logger("An error in the underlying python whois lookup module occured during the lookup of: " + str(question))
			logger("    the error was: " + str(e) )
			lookup_results = {}
                results = json_validator(lookup_results)
                update_cache(question,results)
                if threading.currentThread().getName() != 'backlog_worker':
                    rate_limit_timestamp=datetime.datetime.now()
                return results
Example #17
0
 def getWhoIs(self, dom):
   """
   Return a dictionary of whois infomation
   Will throw exception if tld server not known, or query limit reached
   """
   ws = whois.query(dom)
   return ws.__dict__;
Example #18
0
def run():
    for item in range(len(data)):
        try:
            time.sleep(3)
            domain = whois.query(data.values[item, 0])
            domain_creation = domain.creation_date
            datetimeFormat = '%Y-%m-%d %H:%M:%S'
            diff = datetime.datetime.strptime(
                str(today_date), datetimeFormat) - datetime.datetime.strptime(
                    str(domain_creation), datetimeFormat)
            if (int(diff.days) < 30):
                print("%s domain is possibly malicious" % data.values[item, 0])
                logging.info(
                    "[*] %s domain is probably malicious. domain creation date is %s"
                    % (data.values[item, 0], domain_creation))
            else:
                print("%s domain creation date is : %s " %
                      (data.values[item, 0], domain_creation))

        except KeyboardInterrupt:
            print("[*] Program exited")
            sys.exit()

        except Exception as im:
            if "DOMAIN NOT FOUND" in str(im):
                print("[*] ERROR : %s domain not found " %
                      data.values[item, 0])
            elif "Unknown TLD" in str(im):
                print("[*] ERROR : %s domain has an unknown TLD " %
                      data.values[item, 0])
            else:
                continue
Example #19
0
 def score_domain(self, newsurl):
     domain_score = 0.5
     domain = whois.query(newsurl)
     if domain is not None:
         daysalive = (datetime.datetime.now() - domain.creation_date).days
         # 0 days is 0, 365 is 0.5, 730 is 1
         domain_score = min(daysalive, 730) / 730
Example #20
0
 def whois(self, mess, args):
     """
     Display whois information about a given IP/domainname.
     """
     domain = whois.query(args.domain)
     return '\n'.join(
         ['%25s : %s' % (k, v) for k, v in domain.__dict__.items()])
Example #21
0
def dispatcher(worker):
    while True:
        # Генерируем домен
        query_name = (generator(Settings.domain_level, Settings.domain_symbols))
        # Проверяем наличие домена в DNS
        ar = AsyncResolver([query_name+Settings.domain_zone])
        resolved = ar.resolve()
        # Цикл для проверки есть ли ip у домена
        for host, ip in resolved.items():
            # Если ip нету в DNS то проверяем домен через WHOIS, сразу через WHOIS проверять нельзя
            # Так как это долго и они банят
            if ip is None:
                # Выводим информацию что ip нету в DNS
                # print("\033[92m%s could not be resolved.\033[0m" % (host))
                # Обращаемся в WHOIS, если домен занят - выводим дату до которой
                # он зарегистрирован, если свободен то пишем это и записываем
                # домен в файл
                try:
                    domain = whois.query(host)
                    print("%s%s taken, expiration date %s%s" % (ConsoleColors.OKBLUE, host, domain.expiration_date, ConsoleColors.ENDC))
                except AttributeError:
                    print("%sFREE %s%s" % (ConsoleColors.OKGREEN, host, ConsoleColors.ENDC))
                    Settings.domainsFoundFile.write(host + '\n')
                except Exception:
                    print("%sERROR on %s: whois - You have exceeded allowed connection rate%s" % (ConsoleColors.FAIL, host, ConsoleColors.ENDC))
                time.sleep(2)
Example #22
0
def is_available(domain):
    try:
        w = whois.query(domain)
        if w:
            return False
    except:
        return True
def score_url(newsurl):
    # whitelisting of the domain
    if newsurl is None:
        raise ValueError('Requires valid URL')
    whitelist_score = 0.5
    whitelist_score = whitelist.get(newsurl.lower(), whitelist_score)

    # what is the content of the page
    content_score = 0.5
    r = requests.get(newsurl)
    if r.status_code == 200:
        soup = BeautifulSoup(r.text)
        text = soup.get_text().lower()
        for keyword in keywords:
            if keyword in text:
                content_score = max(content_score - 0.1, 0)

    # whois the domain (age)
    domain_score = 0.5
    domain = whois.query(newsurl)
    if domain is not None:
        today = date.today()
        daysalive = (today - domain.creation_date)
        # 0 days is 0, 365 is 0.5, 730 is 1
        domain_score = min(max(0, daysalive.days), 730) / 730

    score = (whitelist_score + content_score + domain_score) / 3

    return json({'score': score})
def getWhoIsData(dataDict, errorURLList, sitesList, startIndex, divisionFactor):
    #divisionFactor is the number of chunks sitesList will be split in
    if startIndex >= len(sitesList):
        #if we've gone through all the data
        print "finished getting data"
        return dataDict, errorURLList
    else:
        stopIndex = startIndex + int(math.ceil(float(len(sitesList)/divisionFactor)))
        for index in range(startIndex, stopIndex):
            #for each website in this section of the list, get its data
            try:
                dataDict[sitesList[index]] = whois.query(sitesList[index]).__dict__
            except IndexError:
                pass
                '''
                this program correctly computes how many chunks it needs to 
                break the list up into but it won't correctly stop in the middle
                of the last chunk if the last chunk isn't full.  this means that 
                this error will only happen on the last chunk so it's ok to 
                catch it and not worry
                '''
            except:
                #if this site isn't on whois:
                    errorURLList.append(sitesList[index])
        #recursive call on a timer with stopIndex as the new startIndex
        return threading.Timer(1, lambda: getWhoIsData(dataDict, errorURLList, \
        sitesList, stopIndex, divisionFactor)).start()
Example #25
0
def get_domain_expiration_date(domain):
    try:
        domain_info = whois.query(domain)
        return domain_info.expiration_date
    except AttributeError:
        return None
    except ValueError:
        return None
Example #26
0
 def __init__(self, domain):
     domainlookup = whois.query(domain)
     self.name_servers = list(domainlookup.name_servers)
     self.owner = str(domainlookup.registrar)
     self.servers = list(domainlookup.name_servers)
     self.creation = str(domainlookup.creation_date)
     self.experation = str(domainlookup.expiration_date)
     self.update = str(domainlookup.last_updated)
Example #27
0
def checkAvailability(domain):
    results = whois.query(domain)
    print(domain)
    print(available_hazardous)
    if results is None:
        print(available_hazardous)
        available_hazardous.add(domain)
        print(available_hazardous)
Example #28
0
def query(domain, host=None):
    print('-' * 80)
    print("Domain: {0}, host: {1}".format(domain, host))
    w = whois.query(domain, host, ignore_returncode=1)
    if w:
        wd = w.__dict__
        for k, v in wd.items():
            print('%20s\t"%s"' % (k, v))
Example #29
0
def get_whois_info(domain, timeout=10):
    tld = get_tld(domain)
    try:
        with TimeLimiter(timeout):
            info = whois.query(str(tld))
            return dict(info.__dict__)
    except:
        return dict()
Example #30
0
def whois_form():
    info = ''
    if request.method == 'POST':
        domain = request.form['domain']
        query = whois.query(domain)
        info = pprint.pformat(query.__dict__,
                              indent=4) if query is not None else 'Not found'
    return render_template(TEMPLATE, info=info)
def abnormal_url(domain, url):
    try:
        w = whois.query(domain)
        hostname = w.name
        match = re.search(hostname, url)
        return 1 if match else -1
    except Exception as e:
        return -1
 def _get_whois(self, domain):
     try:
         ext = tldextract.extract(domain)
         query_domain = ".".join([ext.domain, ext.suffix])
         whois_info = whois.query(query_domain)
         return whois_info
     except Exception:
         return None
Example #33
0
def get_whois():
    """
    Gives the following exception:
    whois.exceptions.UnknownTld: Unknown TLD: es/
    """
    who_is = whois.query(page)
    with open(f"{folder}whois.txt", "w") as f:
        json.dump(who_is.__dict__, f, indent=4)
Example #34
0
 def domain_lifetime(self):
     try:
         domain = whois.query(urlparse(self.url).netloc)
         lifetime = datetime.datetime.now() - domain.creation_date
         return lifetime.days, None
     except Exception as e:
         print(e)
         return None, e
Example #35
0
def query(domain, host=None):
    print('-' * 80)
    print("Domain: {0}, host: {1}".format(domain, host))
    w = whois.query(domain, host, ignore_returncode=1)
    if w:
        wd = w.__dict__
        for k, v in wd.items():
            print('%20s\t"%s"' % (k, v))
Example #36
0
def func_whois(_domain):
    querywhois = whois.query(_domain)
    for _domain in querywhois.name_servers:
        print("Servidor NDS:",_domain)

    print("Data de registro:", querywhois.creation_date)
    print("Data de Expiracao:", querywhois.expiration_date)
    print("Ultima atualizacao:", querywhois.last_updated)
    print("Registro Whois em:", querywhois.registrar)
Example #37
0
    def whois(self, mess, args):
        """
        Display whois information about the given IP / machine name
        """
        if not args:
            return 'What should I look for ?'

        domain = whois.query(str(args))
        return '\n'.join(['%25s : %s' % (k,v) for k,v in domain.__dict__.iteritems()])
Example #38
0
def get_domain_expiration_date(domain_name):
    status_of_pay = []
    for url in domain_name:
        if url.startswith('http://'):
            url = url.replace(url, url.partition('http://')[2])
        exp_date = whois.query(url).expiration_date - \
            datetime.timedelta(days=31)
        status_of_pay.append(exp_date.month >= 1)
    return status_of_pay
Example #39
0
def dom_chk(x):
	time.sleep(1)
	print 'check - ',x
	domain = whois.query(x)
	try:
	    domain.name
	except Exception, detail:
	    print "Domain %s non occupied" %x
	    good.write(x+"\n")
Example #40
0
 def get_details(self, url):
     if url == None:
         details = None
     else:
         try:
             details = whois.query(url)
         except:
             details = None
     return details
def get_domain_expiration_date(domain_name):
    if domain_name is not None:
        response = whois.query(domain_name)
        if response is not None:
            month_later = datetime.today() + timedelta(days=30)
            return response.expiration_date > month_later
        else:
            return False
    return True
Example #42
0
def currentwhois(domain):
    who = whois.query(domain)
    print "Domain Name %s" % who.name
    print "Registrar   %s" % who.registrar
    print "Expiration  %s" % who.expiration_date
    print "Registrar   %s" % who.registrar
    for ns in who.name_servers:
        print "NameServer  %s" % ns
    # print(who.__dict__)

    print '{0:15} ==> {1:20}'.format('Domain Name', who.name)
    def domain(self):
        """
        Provides a memoized ``domain`` object as returned by the ``whois`` library.

        If the domain is non-existent, or whois information cannot be found, :py:exc:`~peace_of_mind.domains.WHOISNotFoundError` will be raised.
        """
        if not self._domain:
            self._domain = whois.query(self._domain_name)
        if not self._domain:
            raise WHOISNotFoundError("Could not find WHOIS information for {}".format(self._domain_name))
        return self._domain
Example #44
0
def check_whois(ahost):
    """Check whois for the domain"""
    domain = ahost.partition('.')[2]
    domain = whois.query(ahost)
    print "Whois information:"
    print "Registrar: " + str(domain.registrar)
    print "Creation date: " + str(domain.creation_date)
    print "Expiration date: " + str(domain.expiration_date)
    print "Name servers: " 
    for ns_servers in domain.name_servers:
        print "\t" + ns_servers
    def does_it_exist(self, domain=None):
        """
            Uses pywhois to lookup the domain.
            We could also check that the site owner email matches the records found.
        """
        result = whois.query(self.site.fqdn)

        if not result.expiration_date > now():
            return False

        print result.__dict__
        return True
 def __domaain_age(self):
     status = "Cheacking age of domain"
     self.myqueue.put(status)
     try:
         query =  whois.query(self.__request_url)
         last_updated = query.last_updated
         creation_date = query.creation_date
         self.__age_of_domain =  (datetime.today() - creation_date).days
         self.__age_last_modified = (datetime.today() - last_updated).days        
     except:
         self.__age_of_domain =  0
         self.__age_last_modified = 0      
Example #47
0
 def extract_whois(self, domain): # extract whois data from target domain
     try:
         import whois
         d = whois.query(domain, ignore_returncode=True) # ignore return code
         if d.creation_date is None: # return when no creation date
             return
         else:
             print " -Registrant   : " + str(d.registrar)
             print " -Creation date: " + str(d.creation_date)
             print " -Expiration   : " + str(d.expiration_date)
             print " -Last update  : " + str(d.last_updated)
     except: # return when fails performing query
         return
 def f13_whois_networksolutions(self, fqdn):
     """
     Registrar in whois == Network Solutions LLC if not a subdomain?
     """
     if len(fqdn.split('.')) - 1 == 1:
         try:
             if whois.query(fqdn) == 'NETWORK SOLUTIONS, LLC.':
                 return 1
             return -1
         except:
             return -1
     else:
         return -1
Example #49
0
    def _whoisGetter(self):
        while True:
            gevent.sleep(0)
            for nextTask in self._domainsQueue.get().items():
                result = None
                domain, resultReadyCallback = nextTask
                try:
                    result = whois.query(domain, ignore_returncode=True)
                except Exception as ex:
                    print type(ex)
                    print ex

                resultReadyCallback(result)
Example #50
0
 def generate_domains(self):
     i = 0
     for domain in self.domains:
         i = i + 1
         print "checking domain %s %i/%i" % (domain, i, len(self.domains))
         try:
             if not whois.query(str(domain)):
                 twitter_flag = self.check_twitter_handle(domain)
                 print '=> Marked as free: %s %s' % (domain, twitter_flag)
                 self.outfile.write(domain + ' ' + twitter_flag + '\n')
             else:
                 print "Domain %s is not available" % domain
         except Exception, e:
             print "Could not fetch info about domain because =>"
             print "%s" % e
             pass
Example #51
0
def isRecentlyUpdate(domain):
    import whois
    import math
    import datetime
    try: 
        w = whois.query(domain)
        diff= w.last_updated - datetime.datetime.now()
        val= math.fabs(diff.days)
        if (val) >= 365: #less than a year since last updated
            return False
        else:
            score= float(val)/365.0
            return score
    except:
        #print "Can't Find Info for: ", domain
        #cannot find any info for domain which is potential evil domain indicator
        return 0.0
Example #52
0
def whoisRequest(p):

### Pending to count and save domains which couldn't be analyzed for different reasons
	try:
		domain = whois.query(p)
		date = domain.creation_date
		ns = domain.name_servers
		ns_list = []
		for i in ns:
			ns_list.append(i)
		nsfinal = ns_list[0]		
		
		registrar = domain.registrar
		checkDate(p,date,registrar,nsfinal)

	except:
		pass
Example #53
0
def submit():
    word = request.form["keyword"]
    if not word:
        return "<div>Please input keyword!</div>"
    keywords = Keyword.objects.filter(word=word)
    if keywords:
        keyword = keywords[0]
    else:
        keyword = Keyword(word=word)
    domain = whois.query("%s.com" % str(word))
    keyword.website = {"exist": bool(domain)}
    for platform in PLATFORMS:
        keyword.__setattr__(platform, {"exist": fetch(platform, word)})
    keyword.save()
    platforms = dict((key, keyword.__getattribute__(key)) for key in PLATFORMS)
    platforms["website"] = keyword.website
    return render_template("result.html", platforms=platforms)
Example #54
0
def do_whois(n, domain):
	whoiss = {}
	tlds = domain["resolve"].keys()
	for t in tlds:
		if domain["resolve"][t] == 1:
			whoiss[t] = 1
			continue

		try:
			w = whois.query(n+t)
			whoiss[t] = 1
		except:
			whoiss[t] = 0
			traceback.print_exc()
	if len(whoiss.keys()):
		domain["whois"] = whoiss
	
	return domain
def main():
    domain = whois.query(cliargs.domain)
    if not domain:
        print "CRITICAL Couldn't resolve host " + cliargs.domain
        sys.exit(2)

    now_date = datetime.datetime.now()
    delta = domain.expiration_date - now_date
    expire_days = delta.days

    if expire_days <= int(cliargs.critical):
        print ("CRITICAL Domain " + cliargs.domain + " expired in next " + str(expire_days) + " day(s)")
        sys.exit(2)
    elif expire_days <= int(cliargs.warning):
        print ("WARNING Domain " + cliargs.domain + " expired in next " + str(expire_days) + " day(s)")
        sys.exit(1)
    else:
        print ("OK Domain " + cliargs.domain + " expired in next " + str(expire_days) + " day(s)")
        sys.exit(0)
Example #56
0
File: core.py Project: lig/webwhois
    def post(self):
        names = self.request.POST['domain_list'].replace(',', '').split()
        tld_list = self.request.POST.getall('tld_list')
        
        result = {}
        tlds = OrderedDict()

        for tld in TLDS:
            tlds.update({tld: tld in tld_list})

            if tlds[tld]:

                for name in names:
                    domain_tup = (name, tld)
                    result.update(
                        {domain_tup:
                            bool(whois.query(str('%s.%s' % domain_tup)))})

        return {'result': result, 'names': names, 'tlds': tlds}
Example #57
0
def checkShortLife(domain):
    import whois
    import math
    import datetime
 
    try: 
     
        w = whois.query(domain)
        diff=w.creation_date-datetime.datetime.now()
        diff= math.fabs(diff.days)
        if diff<= 30:
            print "Short: ", domain, "Days: ", diff
            return True
        else:
            return False
 
 
    except:
        print "Can't Find Info for: ", domain
        return True
Example #58
0
def diffDomain(domainName):
    '''given a domain name, will compare current whois record to most recent cache of whois entry and report any differences'''
    currRecord=whois.query(domainName)
    currRecordEpoch=time.mktime(time.gmtime())
    sys.stdout.write('Name: {0}\n'.format(currRecord.name))
    sys.stdout.write('Registrar: {0}\n'.format(currRecord.registrar))
    sys.stdout.write('DNS: {0}\n'.format(currRecord.name_servers))
    sys.stdout.write('Exp: {0}\n'.format(currRecord.expiration_date))
    currRecordFile=open('{0}.{1}.stillis'.format(domainName,currRecordEpoch),'w')
    currRecordContent=pickle.dumps(currRecord)
    currRecordFile.write(currRecordContent)
    currRecordFile.close()
  
    for dfile in glob.glob('{0}*stillis'.format(domainName)):
        sys.stdout.write('Examining: {0}'.format(dfile))
        dfileContent=open(dfile).read()
        if dfileContent==currRecordContent:
            sys.stdout.write('\tMatches \n')
        else:
            sys.stdout.write('\tNo match \n')
Example #59
0
    def check(self, domain):
        """Looks up the whois info for the domain in question and attempts to extract the registrar"""
        import whois
        score = 0
        reason = "Registrar could not be determined"

        try:
            registrar = whois.query(domain).registrar
            if "godaddy" in registrar.lower():
                score = -2
                reason = "Registrar, %s, is known to be evil and of low quality. Additionally, their CEO hunts elephants and they support SOPA." % registrar
            if score == 0: # registrar not listed
                reason = "The registrar, %s, is not known to be particularly bad or good. If you feel this is an oversight on our part, feel free to file a bug or pull request" % registrar
        except Exception as e:
            score = 0
            reason = e


        result = {
            "score": score,
            "reason": reason
        }
        return result
Example #60
0
def get_whois(doc):
    """we are going to split out the domain from the url and lookup the ip address
        then we get both whois ip and domain name info"""

    #extract domain info
    domain = tldextract.extract(doc['url']).registered_domain
    hostname = doc['url'].split('/')[2]
    doc['hostname'] = hostname
    doc['ip'] = ''
    doc['whois'] = {}

    try:
        #lookup ip address
        doc['ip'] = socket.gethostbyname(hostname)

    except:
        syslog.syslog('[*] Failed to get ip addr for %s' % hostname)
        print('[*] Failed to get ip addr for %s' % hostname) 
        return doc 

    #now lets lookup ip whois
    try:
        doc['whois']['nets'] = IPWhois(doc['ip']).lookup()['nets']

    except:
        syslog.syslog('[*] Failed to get ip whois for %s' % doc['ip'])
        print('[*] Failed to get ip whois for %s' % doc['ip'])

    #now lets try to get domain name registrar
    try:
        doc['whois']['registrar'] = whois.query(domain).registrar

    except:
        syslog.syslog('[*] Failed to get registrar info for %s' % domain) 
        print('[*] Failed to get registrar info for %s' % domain)    

    return doc