En artÃculos anteriores ya explicamos como acceder a las APIs de OVH/GoDaddy, en esta ocasión programaremos un script que combina ambas APIs para localizar un dominio en concreto, además generará un fichero de caché para agilizar la búsqueda y la posibilidad de consultar la información WHOIS/DNS del dominio en caso de no encontrarlo en ningún panel.
Instalamos las librerÃas necesarias:
Programamos el script, este se conectará a las APIs de OVH/GoDaddy y dumpeará todos los dominios, generará un fichero de caché y buscará en este, en futuras ejecuciones si se detecta la existencia del fichero de caché se buscará directamente en este.
Si el dominio no se encuentra se regenera la caché y si ahún asà no lo encuentra consultará la información WHOIS/DNS.
#!/usr/bin/env python3
import ovh
import os
import time
from cymruwhois import Client as cymruwhoisClient
import socket
import re
from godaddypy import Client, Account
import dns.resolver
# pip install ovh cymruwhois godaddypy dnspython
tmpFile = '/tmp/domainInfo.log'
configFileOvh = 'configs/lista_ids_ovh.list'
configFileGoDaddy = 'configs/lista_ids_godaddy.list'
os.system('clear')
print('')
print('##################################################################')
print('| OVH-GoDaddy Domain/Whois searcher system v0.7b - coded by Kr0m |')
print('| Cache data file path: %s |' % tmpFile)
print('##################################################################')
print('')
def searchDomain(domain):
print('-- Searching domain: %s' % domain)
with open(tmpFile) as f:
lines = f.readlines()
for line in lines:
dataId = line.split()[0]
dataISP = line.split()[1]
dataDomain = line.split()[2]
if domain == dataDomain:
info = dataId + ' ' + dataISP
return info
return 'NULL'
def refreshData():
f = open(tmpFile, 'w')
print('')
print('>> Retriving domain information from OVH....')
for line in open(configFileOvh,'r').readlines():
#print('Line: %s' % line)
ovhId = line.split(':')[0]
ovhKey = line.split(':')[1]
ovhSecret = line.split(':')[2]
ovhConsumer = line.split(':')[3]
ovhRealId = line.split(':')[4].rstrip("\n")
APPLICATION_KEY = ovhKey
APPLICATION_SECRET = ovhSecret
CONSUMER_KEY = ovhConsumer
client = ovh.Client(
endpoint = 'ovh-eu',
application_key = APPLICATION_KEY,
application_secret = APPLICATION_SECRET,
consumer_key = CONSUMER_KEY,
)
print('-- Retrieving domains info from id: %s' % ovhId)
domains=client.get('/domain')
if domains:
for domain in domains:
data = ovhRealId + ' OVH ' + domain + '\n'
f.write(data)
else:
print('-- No Domains found for ID: %s' % ovhId)
print('')
print('>> Retriving domain information from GoDaddy....')
for line in open(configFileGoDaddy,'r').readlines():
daddyName = line.split(':')[0]
daddyKey = line.split(':')[1]
daddySecret = line.split(':')[2]
daddyId = line.split(':')[3].rstrip("\n")
#print('daddyName: %s ' % daddyName)
#print('daddyKey: %s ' % daddyKey)
#print('daddySecret: %s ' % daddySecret)
#print('daddyId: %s ' % daddyId)
print('-- Retrieving domains info from id: %s' % daddyName)
my_acct = Account(api_key=daddyKey, api_secret=daddySecret)
delegate_acct = Account(api_key=daddyKey, api_secret=daddySecret, delegate=daddyId)
client = Client(my_acct)
delegate_client = Client(delegate_acct)
domains = client.get_domains()
if domains:
for domain in domains:
#print('-- Domain: %s' % domain)
data = daddyId + ' GoDaddy ' + domain + '\n'
f.write(data)
else:
print('-- No Domains found for ID: %s' % daddyName)
f.close()
while True:
if not os.path.isfile(tmpFile):
print('-- Previous data file not found, refreshing data.')
refreshData()
print('-- Done')
print('')
domain = input("Wich domain would you like to search > ")
id = searchDomain(domain)
if id == 'NULL':
print('-- Domain not found in previous data, refreshing data.')
refreshData()
print('-- Done.')
print('-- Retrying previous search.')
id = searchDomain(domain)
if id == 'NULL':
print('')
print('++ Domain NOT found.')
print('>> Quering WHOIS/DNS info.')
ip = socket.gethostbyname(domain)
print('Ip: %s' % ip)
c = cymruwhoisClient()
domainWhois = c.lookup(ip)
print('Owner: %s' % domainWhois.owner)
nameservers = dns.resolver.query(domain,'NS')
for nameserver in nameservers:
print('NS: %s' % nameserver)
else:
print('++ Domain found ID: %s' % id)
print('')
Le asignamos los permisos necesarios:
Generamos los ficheros con las credenciales de acceso a las APIs de
OVH
y
GoDaddy
.
vi configs/lista_ids_ovh.list
NOMBRE_DESCRIPTIVO:OVH_KEY:OVH_SECRET:OVH_CONSUMERKEY:OVH_ID
NOMBRE_DESCRIPTIVO:DADDY_KEY:DADDY_SECRET:DADDY_ID
Ejecutamos el script:
##################################################################
| OVH-GoDaddy Domain/Whois searcher system v0.7b - coded by Kr0m |
| Cache data file path: /tmp/domainInfo.log            |
##################################################################
Wich domain would you like to search > asd.com
++ Domain NOT found.
>> Quering WHOIS/DNS info.
Ip: 198.46.84.198
Owner: INMOTI-1, US
NS: ns3.sungardns.com.
NS: ns1.sungardns.com.
NS: ns2.sungardns.com.