-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #378 from jnaskali/feature/whois
whois plugin
- Loading branch information
Showing
3 changed files
with
36 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from typing import Dict | ||
from .plugin import Plugin | ||
import whois | ||
|
||
class WhoisPlugin(Plugin): | ||
""" | ||
A plugin to query whois database | ||
""" | ||
def get_source_name(self) -> str: | ||
return "Whois" | ||
|
||
def get_spec(self) -> [Dict]: | ||
return [{ | ||
"name": "get_whois", | ||
"description": "Get whois registration and expiry information for a domain", | ||
"parameters": { | ||
"type": "object", | ||
"properties": { | ||
"domain": {"type": "string", "description": "Domain name"} | ||
}, | ||
"required": ["domain"], | ||
}, | ||
}] | ||
|
||
async def execute(self, function_name, **kwargs) -> Dict: | ||
try: | ||
whois_result = whois.query(kwargs['domain']) | ||
if whois_result is None: | ||
return {'result': 'No such domain found'} | ||
return whois_result.__dict__ | ||
except Exception as e: | ||
return {'error': 'An unexpected error occurred: ' + str(e)} |