468. Validate IP Address


https://leetcode.com/problems/validate-ip-address



Runtime: 52 ms, faster than 8.14% of Python3 online submissions for Validate IP Address.
Memory Usage: 14.4 MB, less than 17.74% of Python3 online submissions for Validate IP Address.



```python
import ipaddress
import re

def get_ip_type(address):
    try:
        ip = ipaddress.ip_address(address)

        if isinstance(ip, ipaddress.IPv4Address):
            a = re.findall(r"^0+\d", address)
            b = re.findall(r"0+\d$", address)
            c = re.findall(r"\.0+\d+\.", address)
            #d = re.findall(r"0+\d+\:", address)
            if len(a+b+c)>0:
                return "Neither"
            return "IPv4"
        elif isinstance(ip, ipaddress.IPv6Address):
            splits = address.split(":")
            for i in splits:
                if 1 <= len(i) <= 4:
                    pass
                else:
                    return "Neither"
            return "IPv6"
    except ValueError:
        return "Neither"
        
class Solution:
    def validIPAddress(self, IP: str) -> str:
        #9:08
        return get_ip_type(IP)
        #9:08
        #debug until 9:14
```
