'Check ipaddress validate'

def check_ipaddr_validate(self):

    rule1 = '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.'
    rule2 = '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])'
    ipv4_regex = ('%s%s%s%s%s%s' % ('^', rule1, rule1, rule1, rule2, '$'))
    ipv6_regex = '^(?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}$'
    flag = False
    if bool(re.match(ipv4_regex, self.address)):
        flag = True
        self.ip_ver = 'IPv4'
        if (not self.ntp_ucast_ipv4_validate()):
            flag = False
    elif bool(re.match(ipv6_regex, self.address)):
        flag = True
        self.ip_ver = 'IPv6'
    else:
        flag = True
        self.ip_ver = 'IPv6'
    if (not flag):
        if (self.peer_type == 'Server'):
            self.module.fail_json(msg='Error:    Illegal    server    ip-address.')
        else:
            self.module.fail_json(msg='Error:    Illegal    peer    ip-address.')
