#NEWLINE# def loopback_ips( label ) : #NEWLINE# #INDENT# 'Retrieve loopback IP addresses' #NEWLINE# logger . debug ( 'Retrieve loopback IP addresses' ) #NEWLINE# addresses = [ ] #NEWLINE# if sys . platform . startswith ( 'linux' ) : #NEWLINE# #INDENT# ipre = re . compile ( '^(?P<index>\\d+):\\s+(?P<name>\\S+)\\s+inet6?\\s+(?P<ip>[\\da-f.:]+)/(?P<netmask>\\d+)\\s+.*' ) #NEWLINE# labelre = re . compile ( '.*\\s+lo:(?P<label>\\S+).*' ) #NEWLINE# cmd = subprocess . Popen ( '/sbin/ip -o address show dev lo' . split ( ) , shell = False , stdout = subprocess . PIPE ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ipre = re . compile ( '^inet6?\\s+(alias\\s+)?(?P<ip>[\\da-f.:]+)\\s+(?:netmask 0x(?P<netmask>[0-9a-f]+)|prefixlen (?P<mask>\\d+)).*' ) #NEWLINE# cmd = subprocess . Popen ( '/sbin/ifconfig lo0' . split ( ) , shell = False , stdout = subprocess . PIPE ) #NEWLINE# labelre = re . compile ( '' ) #NEWLINE# #UNINDENT# for line in cmd . stdout : #NEWLINE# #INDENT# line = line . decode ( 'ascii' , 'ignore' ) . strip ( ) #NEWLINE# mo = ipre . match ( line ) #NEWLINE# if ( not mo ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# ip = ip_address ( mo . group ( 'ip' ) ) #NEWLINE# if ( not mo . is_loopback ) : #NEWLINE# #INDENT# if label : #NEWLINE# #INDENT# lmo = labelre . match ( line ) #NEWLINE# if ( ( not lmo ) or ( not lmo . group ( 'label' ) . startswith ( label ) ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# addresses . append ( ip ) #NEWLINE# #UNINDENT# #UNINDENT# logger . debug ( 'Loopback addresses: %s' , addresses ) #NEWLINE# return addresses