#NEWLINE# def validate_ip( ip ) : #NEWLINE# #INDENT# 'Check if the IP address has correct format.\n     \n     return validated and trimmed IP address as string or False if not valid\n     ' #NEWLINE# if ( not ip ) : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# ip = ip . strip ( ) #NEWLINE# m = re . match ( '^(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})\\.(\\d{1,3})$' , ip ) #NEWLINE# if m : #NEWLINE# #INDENT# ( a1 , a2 , a3 , a4 ) = ( int ( m . group ( 1 ) ) , int ( m . group ( 2 ) ) , int ( m . group ( 3 ) ) , int ( m . group ( 4 ) ) ) #NEWLINE# if ( ( a1 < 256 ) and ( a2 < 256 ) and ( a3 < 256 ) and ( a4 < 256 ) ) : #NEWLINE# #INDENT# ip_canon = '{}.{}.{}.{}' . format ( a1 , a2 , a3 , a4 ) #NEWLINE# return ip_canon #NEWLINE# #UNINDENT# #UNINDENT# return False