This class provides utilities for common IP comparisons against known network ranges. The class manages the data within the all_ips collection. IPs within the all_ips collection are limited to a single unique entry and must be a public IP. In addition, metadata surrounding the IPs i
| 27 | |
| 28 | |
| 29 | class IPManager(object): |
| 30 | """ |
| 31 | This class provides utilities for common IP comparisons against known network ranges. |
| 32 | The class manages the data within the all_ips collection. |
| 33 | IPs within the all_ips collection are limited to a single unique entry and must be a public IP. |
| 34 | In addition, metadata surrounding the IPs is stored for contextual understanding of its relevance. |
| 35 | """ |
| 36 | |
| 37 | all_ips_collection = None |
| 38 | _mongo_connector = None |
| 39 | |
| 40 | AKAMAI = "AKAMAI" |
| 41 | Akamai_IPs = None |
| 42 | |
| 43 | AWS = "AWS" |
| 44 | AWS_IPs = None |
| 45 | |
| 46 | AZURE = "AZURE" |
| 47 | Azure_IPs = None |
| 48 | |
| 49 | GCP = "GCP" |
| 50 | GCP_IPs = None |
| 51 | |
| 52 | TRACKED = "TRACKED" |
| 53 | Tracked_CIDRs = None |
| 54 | |
| 55 | UNKNOWN = "UNKNOWN" |
| 56 | |
| 57 | _ZONES = None |
| 58 | |
| 59 | _dns_manager = None |
| 60 | |
| 61 | _logger = None |
| 62 | |
| 63 | def _log(self): |
| 64 | """ |
| 65 | Get the log |
| 66 | """ |
| 67 | return logging.getLogger(__name__) |
| 68 | |
| 69 | def __init__(self, mongo_connector, init_all=False): |
| 70 | """ |
| 71 | The init_all parameter is useful if you need to get access to the partner IP |
| 72 | addresses directly rather than using convenience functions. |
| 73 | """ |
| 74 | self._logger = self._log() |
| 75 | |
| 76 | self._mongo_connector = mongo_connector |
| 77 | self.all_ips_collection = mongo_connector.get_all_ips_connection() |
| 78 | self.ip_zones_collection = mongo_connector.get_ipzone_connection() |
| 79 | self.ipv6_zones_collection = mongo_connector.get_ipv6_zone_connection() |
| 80 | |
| 81 | if init_all: |
| 82 | self.__get_akamai_ips() |
| 83 | self.__get_akamai_ipv6s() |
| 84 | self.__get_aws_ips() |
| 85 | self.__get_aws_ipv6s() |
| 86 | self.__get_azure_ips() |
nothing calls this directly
no outgoing calls
no test coverage detected