def compare_dns_experiments(self, experiment_dns_answers): if self.control['dns']['failure'] is not None and \ self.control['dns']['failure'] == self.report['dns_experiment_failure']: self.report['dns_consistency'] = 'consistent' return True control_addrs = set(self.control['dns']['addrs']) experiment_addrs = set(experiment_dns_answers) if control_addrs == experiment_addrs: return True for experiment_addr in experiment_addrs: if is_public_ipv4_address(experiment_addr) is False: return False if len(control_addrs.intersection(experiment_addrs)) > 0: return True experiment_asns = set(map(lambda x: geoip.ip_to_location(x)['asn'], experiment_addrs)) control_asns = set(map(lambda x: geoip.ip_to_location(x)['asn'], control_addrs)) # Remove the instance of AS0 when we fail to find the ASN control_asns.discard('AS0') experiment_asns.discard('AS0') if len(control_asns.intersection(experiment_asns)) > 0: return True return False
def is_facebook_ip(ip_address): """ :return: True when the IP in questions belongs to the facebook ASN """ try: location = ip_to_location(ip_address) return location['asn'] == 'AS32934' except: return False
def test_ip_to_location(self): location = geoip.ip_to_location('8.8.8.8') assert 'countrycode' in location assert 'asn' in location assert 'city' in location