我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用validators.domain()。
def route_micro(micro): ''' Micro to real URL redirection handler. ''' try: temp = lookup_micro(micro) if urlcheck(temp): return redirect(temp) elif domaincheck(temp): return redirect("http://" + temp) elif ipcheck(temp.split(':')[0]) and urlcheck('http://' + temp): # checks for plain ip or an ip with something after it return redirect("http://" + temp) else: abort(404) except Exception as e: # If micro is not registered, handle the exception from trying to look # it up and raise a 404 HTTP error. sys.stderr.write(str(e)) abort(404)
def search(self): mod.display(self.module_name, "", "INFO", "Searching...") url = "https://openphish.com/" paths = [ "feed.txt" ] for path in paths: content = Cache(self.module_name, url, path, self.search_method).content for line in content.split("\n"): try: midle = line.split("//")[-1].split("/")[0] except: midle = None if self.type == "URL": if self.ioc in line: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return elif self.type == "IPv4" and validators.ipv4(midle): if self.ioc == midle: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return elif self.type == "domain" and validators.domain(midle): if midle == self.ioc: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return
def checkType(self, argument): """ Identify observable type """ if validators.url(argument): return "URL" elif validators.md5(argument): return "MD5" elif validators.sha1(argument): return "SHA1" elif validators.sha256(argument): return "SHA256" elif validators.sha512(argument): return "SHA512" elif validators.ipv4(argument): return "IPv4" elif validators.ipv6(argument): return "IPv6" elif validators.domain(argument): return "domain" else: mod.display("MAIN", argument, "ERROR", "Unable to retrieve observable type") return None
def domain_validator(value): if not validators.domain(value): raise ValidationError("A sintax do domínio informado é inválida")
def __init__(self, ioc, type, config): self.config = config self.module_name = __name__.split(".")[1] self.types = ["domain", "URL", "IPv4"] self.search_method = "Online" self.description = "Search domain in Openphish feeds" self.author = "Conix" self.creation_date = "15-09-2016" self.type = type self.ioc = ioc if type in self.types and mod.allowedToSearch(self.search_method): self.search() else: mod.display(self.module_name, "", "INFO", "OpenPhish module not activated")
def __init__(self, ioc, type, config): self.config = config self.module_name = __name__.split(".")[1] self.types = ["domain", "IPv4", "URL"] self.search_method = "Online" self.description = "Search domain in Lehigh feeds" self.author = "Conix" self.creation_date = "15-09-2016" self.type = type self.ioc = ioc if type in self.types and mod.allowedToSearch(self.search_method): self.search() else: mod.display(self.module_name, "", "INFO", "ZeusTracker module not activated")
def search(self): mod.display(self.module_name, "", "INFO", "Searching...") url = "https://zeustracker.abuse.ch/" paths = [ "blocklist.php?download=baddomains", "blocklist.php?download=ipblocklist", "blocklist.php?download=compromised" ] for path in paths: if self.type == "URL": try: self.ioc = self.ioc.split("://")[1] except: pass content = Cache(self.module_name, url, path, self.search_method).content for line in content.split("\n"): if path.split("=")[1] == "compromised": if self.type == "URL": if self.ioc == line: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return else: line = line.split("/")[0] try: line = line.split(":")[0] except: pass if self.type == "domain" and validators.domain(line.strip()): if line.strip() == self.ioc: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return elif self.type == "IPv4" and validators.ipv4(line.strip()): if line.strip() == self.ioc: mod.display(self.module_name, self.ioc, "FOUND", "%s%s"%(url, path)) return
def checkDomain(value): domain_checked = validators.domain(value) if not domain_checked: raise argparse.ArgumentTypeError('Invalid {} domain.'.format(value)) return value ###################################################################