-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from IKermani/async-support
Async check.
- Loading branch information
Showing
10 changed files
with
185 additions
and
145 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
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 |
---|---|---|
@@ -1,28 +1,39 @@ | ||
"""It's the checker module for filtering status""" | ||
import os | ||
import dns.resolver | ||
import dns.asyncresolver | ||
|
||
blocked_ips = {'10.10.34.34', '10.10.34.35', '10.10.34.36'} | ||
resolver = dns.resolver.Resolver() | ||
resolver.nameservers = [ | ||
'178.22.122.100' if 'CI' in os.environ else '8.8.8.8' | ||
] | ||
headers = ['Address', 'Status'] | ||
|
||
class DomainChecker: | ||
""" | ||
Checks if the domain is blocked or not | ||
""" | ||
headers = ['Address', 'Status'] | ||
|
||
def check(domain: str) -> bool: | ||
"""Check if domain is blocked | ||
def __init__(self, blocked_ips=None): | ||
self.blocked_ips = blocked_ips or { | ||
'10.10.34.34', | ||
'10.10.34.35', | ||
'10.10.34.36', | ||
} | ||
|
||
Args: | ||
domain (str): The domain's name | ||
self.resolver = dns.asyncresolver.Resolver(configure=False) | ||
self.resolver.nameservers = [ | ||
'178.22.122.100' if 'CI' in os.environ else '8.8.8.8' | ||
] | ||
|
||
Returns: | ||
bool: Blocking status | ||
""" | ||
try: | ||
answer = resolver.resolve(domain) | ||
ip_list = [data.address for data in answer] | ||
except dns.resolver.NXDOMAIN: | ||
ip_list = [] | ||
async def acheck(self, domain: str) -> tuple[str, bool]: | ||
"""Check if domain is blocked | ||
Args: | ||
domain (str): The domain's name | ||
Returns: | ||
tuple: (Domain's name, Blocking status) | ||
""" | ||
try: | ||
answer = await self.resolver.resolve(domain) | ||
ip_list = [data.address for data in answer] | ||
except dns.resolver.NXDOMAIN: | ||
ip_list = [] | ||
|
||
return not any(ip in blocked_ips for ip in ip_list) | ||
return domain, not any(ip in self.blocked_ips for ip in ip_list) |
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
Oops, something went wrong.