2015-11-07 10:20:12 +00:00
|
|
|
# PYTHON STUFFS #######################################################
|
|
|
|
|
2014-12-01 17:13:58 +00:00
|
|
|
import datetime
|
|
|
|
import urllib
|
|
|
|
|
2015-10-30 20:57:45 +00:00
|
|
|
from nemubot.exception import IMException
|
2015-01-03 19:34:44 +00:00
|
|
|
from nemubot.tools.web import getJSON
|
|
|
|
|
2014-12-01 17:13:58 +00:00
|
|
|
from more import Response
|
|
|
|
|
2015-11-07 10:20:12 +00:00
|
|
|
URL_AVAIL = "https://www.whoisxmlapi.com/whoisserver/WhoisService?cmd=GET_DN_AVAILABILITY&domainName=%%s&outputFormat=json&username=%s&password=%s"
|
2015-11-07 11:29:53 +00:00
|
|
|
URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?da=2&domainName=%%s&outputFormat=json&userName=%s&password=%s"
|
2014-12-01 17:13:58 +00:00
|
|
|
|
2015-11-07 10:20:12 +00:00
|
|
|
|
|
|
|
# LOADING #############################################################
|
|
|
|
|
2014-12-01 17:13:58 +00:00
|
|
|
def load(CONF, add_hook):
|
2015-11-07 10:20:12 +00:00
|
|
|
global URL_AVAIL, URL_WHOIS
|
2014-12-01 17:13:58 +00:00
|
|
|
|
2015-10-27 17:03:28 +00:00
|
|
|
if not CONF or not CONF.hasNode("whoisxmlapi") or "username" not in CONF.getNode("whoisxmlapi") or "password" not in CONF.getNode("whoisxmlapi"):
|
2015-06-03 20:07:06 +00:00
|
|
|
raise ImportError("You need a WhoisXML API account in order to use "
|
|
|
|
"the !netwhois feature. Add it to the module "
|
|
|
|
"configuration file:\n<whoisxmlapi username=\"XX\" "
|
|
|
|
"password=\"XXX\" />\nRegister at "
|
|
|
|
"http://www.whoisxmlapi.com/newaccount.php")
|
|
|
|
|
2015-11-07 10:20:12 +00:00
|
|
|
URL_AVAIL = URL_AVAIL % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
|
2015-06-03 20:07:06 +00:00
|
|
|
URL_WHOIS = URL_WHOIS % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
|
|
|
|
|
|
|
|
import nemubot.hooks
|
2015-11-16 06:19:09 +00:00
|
|
|
add_hook(nemubot.hooks.Command(cmd_whois, "netwhois",
|
|
|
|
help="Get whois information about given domains",
|
|
|
|
help_usage={"DOMAIN": "Return whois information on the given DOMAIN"}),
|
|
|
|
"in","Command")
|
|
|
|
add_hook(nemubot.hooks.Command(cmd_avail, "domain_available",
|
|
|
|
help="Domain availability check using whoisxmlapi.com",
|
|
|
|
help_usage={"DOMAIN": "Check if the given DOMAIN is available or not"}),
|
|
|
|
"in","Command")
|
2015-11-07 10:20:12 +00:00
|
|
|
|
2014-12-01 17:13:58 +00:00
|
|
|
|
2015-11-07 10:20:12 +00:00
|
|
|
# MODULE CORE #########################################################
|
2014-12-01 17:13:58 +00:00
|
|
|
|
|
|
|
def whois_entityformat(entity):
|
|
|
|
ret = ""
|
|
|
|
if "organization" in entity:
|
|
|
|
ret += entity["organization"]
|
2015-11-07 11:29:53 +00:00
|
|
|
if "organization" in entity and "name" in entity:
|
|
|
|
ret += " "
|
2014-12-01 17:13:58 +00:00
|
|
|
if "name" in entity:
|
|
|
|
ret += entity["name"]
|
|
|
|
|
|
|
|
if "country" in entity or "city" in entity or "telephone" in entity or "email" in entity:
|
|
|
|
ret += " (from "
|
|
|
|
if "street1" in entity:
|
|
|
|
ret += entity["street1"] + " "
|
|
|
|
if "city" in entity:
|
|
|
|
ret += entity["city"] + " "
|
|
|
|
if "state" in entity:
|
|
|
|
ret += entity["state"] + " "
|
|
|
|
if "country" in entity:
|
|
|
|
ret += entity["country"] + " "
|
|
|
|
if "telephone" in entity:
|
|
|
|
ret += entity["telephone"] + " "
|
|
|
|
if "email" in entity:
|
|
|
|
ret += entity["email"] + " "
|
|
|
|
ret = ret.rstrip() + ")"
|
|
|
|
|
|
|
|
return ret.lstrip()
|
|
|
|
|
2015-11-07 10:20:12 +00:00
|
|
|
def available(dom):
|
|
|
|
js = getJSON(URL_AVAIL % urllib.parse.quote(dom))
|
|
|
|
|
|
|
|
if "ErrorMessage" in js:
|
|
|
|
raise IMException(js["ErrorMessage"]["msg"])
|
|
|
|
|
|
|
|
return js["DomainInfo"]["domainAvailability"] == "AVAILABLE"
|
|
|
|
|
|
|
|
|
|
|
|
# MODULE INTERFACE ####################################################
|
|
|
|
|
|
|
|
def cmd_avail(msg):
|
|
|
|
if not len(msg.args):
|
|
|
|
raise IMException("Indicate a domain name for having its availability status!")
|
|
|
|
|
|
|
|
return Response(["%s: %s" % (dom, "available" if available(dom) else "unavailable") for dom in msg.args],
|
|
|
|
channel=msg.channel)
|
|
|
|
|
2014-12-01 17:13:58 +00:00
|
|
|
|
|
|
|
def cmd_whois(msg):
|
2015-07-10 21:09:54 +00:00
|
|
|
if not len(msg.args):
|
2015-10-30 20:57:45 +00:00
|
|
|
raise IMException("Indiquer un domaine ou une IP à whois !")
|
2014-12-01 17:13:58 +00:00
|
|
|
|
2015-07-10 21:09:54 +00:00
|
|
|
dom = msg.args[0]
|
2014-12-01 17:13:58 +00:00
|
|
|
|
2014-12-15 22:57:37 +00:00
|
|
|
js = getJSON(URL_WHOIS % urllib.parse.quote(dom))
|
2014-12-01 17:13:58 +00:00
|
|
|
|
|
|
|
if "ErrorMessage" in js:
|
2015-10-30 20:57:45 +00:00
|
|
|
raise IMException(js["ErrorMessage"]["msg"])
|
2014-12-01 17:13:58 +00:00
|
|
|
|
|
|
|
whois = js["WhoisRecord"]
|
|
|
|
|
2015-11-07 11:29:53 +00:00
|
|
|
res = []
|
|
|
|
|
|
|
|
if "registrarName" in whois:
|
|
|
|
res.append("\x03\x02registered by\x03\x02 " + whois["registrarName"])
|
|
|
|
|
|
|
|
if "domainAvailability" in whois:
|
|
|
|
res.append(whois["domainAvailability"])
|
|
|
|
|
|
|
|
if "contactEmail" in whois:
|
|
|
|
res.append("\x03\x02contact email\x03\x02 " + whois["contactEmail"])
|
|
|
|
|
|
|
|
if "audit" in whois:
|
|
|
|
if "createdDate" in whois["audit"] and "$" in whois["audit"]["createdDate"]:
|
|
|
|
res.append("\x03\x02created on\x03\x02 " + whois["audit"]["createdDate"]["$"])
|
|
|
|
if "updatedDate" in whois["audit"] and "$" in whois["audit"]["updatedDate"]:
|
|
|
|
res.append("\x03\x02updated on\x03\x02 " + whois["audit"]["updatedDate"]["$"])
|
|
|
|
|
|
|
|
if "registryData" in whois:
|
|
|
|
if "expiresDateNormalized" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02expire on\x03\x02 " + whois["registryData"]["expiresDateNormalized"])
|
|
|
|
if "registrant" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02registrant:\x03\x02 " + whois_entityformat(whois["registryData"]["registrant"]))
|
|
|
|
if "zoneContact" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02zone contact:\x03\x02 " + whois_entityformat(whois["registryData"]["zoneContact"]))
|
|
|
|
if "technicalContact" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02technical contact:\x03\x02 " + whois_entityformat(whois["registryData"]["technicalContact"]))
|
|
|
|
if "administrativeContact" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02administrative contact:\x03\x02 " + whois_entityformat(whois["registryData"]["administrativeContact"]))
|
|
|
|
if "billingContact" in whois["registryData"]:
|
|
|
|
res.append("\x03\x02billing contact:\x03\x02 " + whois_entityformat(whois["registryData"]["billingContact"]))
|
|
|
|
|
|
|
|
return Response(res,
|
|
|
|
title=whois["domainName"],
|
|
|
|
channel=msg.channel,
|
|
|
|
nomore="No more whois information")
|