[networking/whois] New function to get domain availability status
This commit is contained in:
parent
a4e6e4ce84
commit
6aef54910e
@ -1,3 +1,5 @@
|
|||||||
|
# PYTHON STUFFS #######################################################
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
@ -6,10 +8,14 @@ from nemubot.tools.web import getJSON
|
|||||||
|
|
||||||
from more import Response
|
from more import Response
|
||||||
|
|
||||||
|
URL_AVAIL = "https://www.whoisxmlapi.com/whoisserver/WhoisService?cmd=GET_DN_AVAILABILITY&domainName=%%s&outputFormat=json&username=%s&password=%s"
|
||||||
URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?rid=1&domainName=%%s&outputFormat=json&userName=%s&password=%s"
|
URL_WHOIS = "http://www.whoisxmlapi.com/whoisserver/WhoisService?rid=1&domainName=%%s&outputFormat=json&userName=%s&password=%s"
|
||||||
|
|
||||||
|
|
||||||
|
# LOADING #############################################################
|
||||||
|
|
||||||
def load(CONF, add_hook):
|
def load(CONF, add_hook):
|
||||||
global URL_WHOIS
|
global URL_AVAIL, URL_WHOIS
|
||||||
|
|
||||||
if not CONF or not CONF.hasNode("whoisxmlapi") or "username" not in CONF.getNode("whoisxmlapi") or "password" not in CONF.getNode("whoisxmlapi"):
|
if not CONF or not CONF.hasNode("whoisxmlapi") or "username" not in CONF.getNode("whoisxmlapi") or "password" not in CONF.getNode("whoisxmlapi"):
|
||||||
raise ImportError("You need a WhoisXML API account in order to use "
|
raise ImportError("You need a WhoisXML API account in order to use "
|
||||||
@ -18,14 +24,20 @@ def load(CONF, add_hook):
|
|||||||
"password=\"XXX\" />\nRegister at "
|
"password=\"XXX\" />\nRegister at "
|
||||||
"http://www.whoisxmlapi.com/newaccount.php")
|
"http://www.whoisxmlapi.com/newaccount.php")
|
||||||
|
|
||||||
|
URL_AVAIL = URL_AVAIL % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
|
||||||
URL_WHOIS = URL_WHOIS % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
|
URL_WHOIS = URL_WHOIS % (urllib.parse.quote(CONF.getNode("whoisxmlapi")["username"]), urllib.parse.quote(CONF.getNode("whoisxmlapi")["password"]))
|
||||||
|
|
||||||
import nemubot.hooks
|
import nemubot.hooks
|
||||||
add_hook("in_Command", nemubot.hooks.Command(cmd_whois, "netwhois",
|
add_hook("in_Command", nemubot.hooks.Command(cmd_whois, "netwhois",
|
||||||
help="Get whois information about given domains",
|
help="Get whois information about given domains",
|
||||||
help_usage={"DOMAIN": "Return whois information on the given DOMAIN"}))
|
help_usage={"DOMAIN": "Return whois information on the given DOMAIN"}))
|
||||||
|
add_hook("in_Command", 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"}))
|
||||||
|
|
||||||
|
|
||||||
|
# MODULE CORE #########################################################
|
||||||
|
|
||||||
def extractdate(str):
|
def extractdate(str):
|
||||||
tries = [
|
tries = [
|
||||||
"%Y-%m-%dT%H:%M:%S.0%Z",
|
"%Y-%m-%dT%H:%M:%S.0%Z",
|
||||||
@ -77,6 +89,24 @@ def whois_entityformat(entity):
|
|||||||
|
|
||||||
return ret.lstrip()
|
return ret.lstrip()
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
def cmd_whois(msg):
|
def cmd_whois(msg):
|
||||||
if not len(msg.args):
|
if not len(msg.args):
|
||||||
|
Loading…
Reference in New Issue
Block a user