#NEWLINE# def get_inet_num( search_term ) : #NEWLINE# #INDENT# '\n\tGet intetnums for a domain\n\t\n\t:param search_term: keywork without dots, no domains are allowed. domain.com -> invalid |---| domain -> valid\n\t:type search_term: str\n\n\t:return: iterable with IP/CIDR notation or None \n\t:rtype: list(str) | None\n\t\n\t' #NEWLINE# requests_log = logging . getLogger ( 'requests' ) #NEWLINE# requests_log . addHandler ( logging . NullHandler ( ) ) #NEWLINE# requests_log . propagate = False #NEWLINE# request = requests . get ( 'http://rest.db.ripe.net/search.json' , params = { #NEWLINE# #INDENT# 'query-string' : search_term , #NEWLINE# 'type-filter' : 'inetnum' , #NEWLINE# #UNINDENT# } ) #NEWLINE# json_results = json . loads ( request . text ) #NEWLINE# try : #NEWLINE# #INDENT# ranges = [ x [ 'primary-key' ] [ 'attribute' ] [ 0 ] [ 'value' ] for x in json_results [ 'objects' ] [ 'object' ] if ( x [ 'type' ] == 'inetnum' ) ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# cidrs = [ ] #NEWLINE# for _range in ranges : #NEWLINE# #INDENT# _range = _range . split ( ' - ' ) #NEWLINE# cidrs . append ( netaddr . iprange_to_cidrs ( _range [ 0 ] , _range [ 1 ] ) ) #NEWLINE# #UNINDENT# results = set ( ) #NEWLINE# for cidr in cidrs : #NEWLINE# #INDENT# results . add ( str ( cidr [ 0 ] ) ) #NEWLINE# #UNINDENT# return results