This class is designed for interacting with PassiveTotal
| 26 | |
| 27 | |
| 28 | class PassiveTotal(object): |
| 29 | """ |
| 30 | This class is designed for interacting with PassiveTotal |
| 31 | """ |
| 32 | |
| 33 | pt_config_file = "connector.config" |
| 34 | KEY = None |
| 35 | TOKEN = None |
| 36 | URL = "https://api.passivetotal.org/v2/" |
| 37 | _logger = None |
| 38 | |
| 39 | def _log(self): |
| 40 | """ |
| 41 | Get the log |
| 42 | """ |
| 43 | return logging.getLogger(__name__) |
| 44 | |
| 45 | def _init_passivetotal(self, config): |
| 46 | self.URL = ConnectorUtil.get_config_setting( |
| 47 | self._logger, config, "PassiveTotal", "pt.url" |
| 48 | ) |
| 49 | self.KEY = ConnectorUtil.get_config_setting( |
| 50 | self._logger, config, "PassiveTotal", "pt.key" |
| 51 | ) |
| 52 | self.TOKEN = ConnectorUtil.get_config_setting( |
| 53 | self._logger, config, "PassiveTotal", "pt.token" |
| 54 | ) |
| 55 | |
| 56 | def __init__(self, config_file="", log_level=None): |
| 57 | if config_file != "": |
| 58 | self.pt_config_file = config_file |
| 59 | |
| 60 | self._logger = self._log() |
| 61 | |
| 62 | if log_level is not None: |
| 63 | self._logger.setLevel(log_level) |
| 64 | |
| 65 | config = configparser.ConfigParser() |
| 66 | list = config.read(self.pt_config_file) |
| 67 | if len(list) == 0: |
| 68 | self._logger.error("Error: Could not find the config file") |
| 69 | exit(1) |
| 70 | |
| 71 | self._init_passivetotal(config) |
| 72 | |
| 73 | def get_name_server(self, name_server): |
| 74 | """ |
| 75 | Fetches the whois records from PassiveTotal based on the registered name_server. |
| 76 | @param name_server The name_server to search for in the whois records. |
| 77 | """ |
| 78 | parameters = {"field": "nameserver", "query": name_server} |
| 79 | req = requests.get( |
| 80 | self.URL + "whois/search", |
| 81 | params=parameters, |
| 82 | auth=HTTPBasicAuth(self.TOKEN, self.KEY), |
| 83 | timeout=120, |
| 84 | ) |
| 85 |
nothing calls this directly
no outgoing calls
no test coverage detected