Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_returns_true_on_valid_domain(value):
assert domain(value)
def _parse_urls(urls, ifile):
""" Parses URLs from CLI args and input file.
"""
target_urls = []
# Parse the URLs.
if urls:
target_urls.extend([_clean(url) for url in urls.split(",")])
if ifile:
with open(ifile) as fp:
for line in fp:
target_urls.append(_clean(line))
# Remove all nonvalid URLs.
for target_url in target_urls:
if not validators.domain(target_url):
click.echo("Invalid URL: {}, Skipping...".format(target_url))
target_urls.remove(target_url)
return target_urls
def check_dominio_analisado(dominio_analisado):
if validators.domain(dominio_analisado):
print('\n\nA sintax do domínio informado é valida\n\n')
else:
print('\n\nA sintax do domínio informado é inválida\n\n')
exit()
def extract_domain(text):
text = clean_comment(text)
names = [x for x in text.split() if is_correct_length(x)]
for name in names:
if is_ip_address(name):
continue
name_idn = decode(name)
if not name_idn:
continue
if '_' in name_idn:
continue
if validators.domain(name_idn):
return name_idn
return None
style("host", bold=True, fg="yellow"),
)
)
sys.exit(1)
team_name = click.prompt("Enter team name", type=str)
if click.confirm(
"Please confirm the team name - {}".format(team_name), abort=True
):
team_url = ""
if click.confirm(
"Do you want to enter the Team URL".format(team_name)
):
team_url = click.prompt("Team URL", type=str)
while not (
validators.url(team_url) or validators.domain(team_url)
):
echo(style("Sorry, please enter a valid link.", bold=True, fg="red"))
team_url = click.prompt("Team URL", type=str)
is_host = team == "host"
create_team(team_name, team_url, is_host)
set_whitelist.update(line for line in (line.strip() for line in fOpen)
if line and not line.startswith(('!', '#')) and validatedomain(line))
# Convert filters to string format
str_hosts_and_filters = '\n'.join(set_hosts_and_filters)
# Extract valid restrictive filters
list_valid_filters = valid_filter_pattern.findall(str_hosts_and_filters)
# Extract valid whitelist filters
list_valid_whitelist = valid_whitelist_pattern.findall(str_hosts_and_filters)
# If there are valid restrictive filters
if list_valid_filters:
# Add the valid domains to the restrictive filter set
for domain in list_valid_filters:
if validatedomain(domain):
set_restrictive_filters.add(domain)
# If there are valid whitelist filters
if list_valid_whitelist:
# Add the valid domains to the whitelist set
for domain in list_valid_whitelist:
if validatedomain(domain):
set_whitelist.add(domain)
# Remove exact matches between whitelist and restrictive filters
set_restrictive_filters.difference_update(set_whitelist)
# Add @@|| prefix and ^ suffix to verified whitelist matches
set_whitelist = {f'@@||{x}^' for x in set_whitelist}
# Remove sub-domains
def getAnonymizedIpOrDomain(value):
if validators.ipv4(value) or validators.ipv6(value):
return "" % hashlib.md5(value).hexdigest()
elif validators.domain(value):
return "" % hashlib.md5(value).hexdigest()
else:
return "" % hashlib.md5(value).hexdigest()
def is_valid_aens_name(domain_name):
"""
Test if the provided name is valid for the aens system
"""
if domain_name is None or not validators.domain(domain_name.lower()) or (
not domain_name.endswith(('.chain')) and not domain_name.endswith(('.test'))):
return False
return True
def process_iocs(provided_iocs):
"""Return data formatted for Splunk from ThreatCrowd."""
splunk_table = []
for provided_ioc in set(provided_iocs):
provided_ioc = provided_ioc.replace("[.]", ".")
provided_ioc = provided_ioc.replace("[d]", ".")
provided_ioc = provided_ioc.replace("[D]", ".")
if validators.ipv4(provided_ioc) or validators.domain(provided_ioc):
ioc_dicts = process_host(provided_ioc)
elif validators.email(provided_ioc):
ioc_dicts = process_email(provided_ioc)
else:
splunk_table.append({"invalid": provided_ioc})
continue
for ioc_dict in ioc_dicts:
splunk_table.append(ioc_dict)
if len(provided_iocs) > 1:
sleep(10)
return splunk_table