<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import re <EOL> import socket <EOL> from salt . ext . six import string_types <EOL> import salt . utils <EOL> if salt . utils . is_windows ( ) : <EOL> from salt . ext import win_inet_pton <EOL> def mac ( addr ) : <EOL> '''<STR_LIT>''' <EOL> valid = re . compile ( r'''<STR_LIT>''' , <EOL> re . VERBOSE | re . IGNORECASE ) <EOL> return valid . match ( addr ) is not None <EOL> def __ip_addr ( addr , address_family = socket . AF_INET ) : <EOL> '''<STR_LIT>''' <EOL> mask_max = '<STR_LIT>' <EOL> if address_family == socket . AF_INET6 : <EOL> mask_max = '<STR_LIT>' <EOL> try : <EOL> if '<STR_LIT:/>' not in addr : <EOL> addr = '<STR_LIT>' . format ( addr = addr , mask_max = mask_max ) <EOL> except TypeError : <EOL> return False <EOL> ip , mask = addr . rsplit ( '<STR_LIT:/>' , <NUM_LIT:1> ) <EOL> try : <EOL> socket . inet_pton ( address_family , ip ) <EOL> except socket . error : <EOL> return False <EOL> try : <EOL> mask = int ( mask ) <EOL> except ValueError : <EOL> return False <EOL> else : <EOL> if not <NUM_LIT:1> <= mask <= int ( mask_max ) : <EOL> return False <EOL> return True <EOL> def ipv4_addr ( addr ) : <EOL> '''<STR_LIT>''' <EOL> return __ip_addr ( addr , socket . AF_INET ) <EOL> def ipv6_addr ( addr ) : <EOL> '''<STR_LIT>''' <EOL> return __ip_addr ( addr , socket . AF_INET6 ) <EOL> def netmask ( mask ) : <EOL> '''<STR_LIT>''' <EOL> if not isinstance ( mask , string_types ) : <EOL> return False <EOL> octets = mask . split ( '<STR_LIT:.>' ) <EOL> if not len ( octets ) == <NUM_LIT:4> : <EOL> return False <EOL> return ipv4_addr ( mask ) and octets == sorted ( octets , reverse = True ) </s>
