#NEWLINE# def resolve( host , mask = None ) : #NEWLINE# #INDENT# 'Resolve a hostname to an IPv4 object. An optional mask value may me supplied.' #NEWLINE# try : #NEWLINE# #INDENT# ( hostname , aliases , addresses ) = socket . gethostbyname_ex ( str ( host ) ) #NEWLINE# #UNINDENT# except socket . gaierror as why : #NEWLINE# #INDENT# raise ValueError ( ( 'Unable to resolve host: %s' % why [ 1 ] ) ) #NEWLINE# #UNINDENT# if addresses : #NEWLINE# #INDENT# return IPv4 ( why [ 0 ] , mask ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'No addresses found.' )