Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
169 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from functools import partial | ||
from typing import Optional | ||
|
||
import aiometer | ||
|
||
from abuse_whois.matchers.shared_hosting import get_shared_hosting_provider | ||
from abuse_whois.matchers.whois import get_contact_from_whois | ||
|
||
from .errors import InvalidAddressError | ||
from .ip import resolve_ip_address | ||
from .schemas import Contact, Contacts | ||
from .utils import ( | ||
get_hostname, | ||
get_registered_domain, | ||
is_domain, | ||
is_ip_address, | ||
is_supported_address, | ||
) | ||
|
||
|
||
async def get_contact(domain_or_ip_address: Optional[str] = None) -> Optional[Contact]: | ||
if domain_or_ip_address is None: | ||
return None | ||
|
||
return await get_contact_from_whois(domain_or_ip_address) | ||
|
||
|
||
async def get_registrar_and_hosting_provider_contacts( | ||
*, domain: Optional[str] = None, ip_address: Optional[str] = None | ||
): | ||
values = [domain, ip_address] | ||
return await aiometer.run_all([partial(get_contact, value) for value in values]) | ||
|
||
|
||
async def get_abuse_contacts(address: str) -> Contacts: | ||
if not is_supported_address(address): | ||
raise InvalidAddressError(f"{address} is not supported type address") | ||
|
||
shared_hosting_provider: Optional[Contact] = None | ||
registrar: Optional[Contact] = None | ||
hosting_provider: Optional[Contact] = None | ||
|
||
hostname = get_hostname(address) | ||
|
||
domain: Optional[str] = None # FQDN | ||
ip_address: Optional[str] = None | ||
registered_domain: Optional[str] = None | ||
|
||
shared_hosting_provider = get_shared_hosting_provider(hostname) | ||
|
||
if is_domain(hostname): | ||
domain = hostname | ||
registered_domain = get_registered_domain(hostname) | ||
|
||
# get IP address by domain | ||
try: | ||
ip_address = await resolve_ip_address(hostname) | ||
except OSError: | ||
pass | ||
|
||
if is_ip_address(hostname): | ||
ip_address = hostname | ||
|
||
registrar, hosting_provider = await get_registrar_and_hosting_provider_contacts( | ||
domain=domain, ip_address=ip_address | ||
) | ||
|
||
return Contacts( | ||
address=address, | ||
hostname=hostname, | ||
ip_address=ip_address, | ||
registered_domain=registered_domain, | ||
shared_hosting_provider=shared_hosting_provider, | ||
registrar=registrar, | ||
hosting_provider=hosting_provider, | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from abuse_whois import __version__ | ||
|
||
|
||
def test_version(): | ||
assert isinstance(__version__, str) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.