
At Meta, systems such as network-facing services and internal traffic filters need strict IP parsing. Implement a function that takes a string and returns whether it is a valid IPv4 address, valid IPv6 address, or Neither.
Write a function validate_ip(address) that accepts a string address and returns one of:
"IPv4" if the string is a valid IPv4 address"IPv6" if the string is a valid IPv6 address"Neither" otherwiseA valid IPv4 address has exactly 4 decimal parts separated by .. Each part must contain only digits, be in the range 0 to 255, and must not contain leading zeros unless the part is exactly "0".
A valid IPv6 address has exactly 8 parts separated by :. Each part must be 1 to 4 characters long and contain only hexadecimal characters: 0-9, a-f, or A-F.
Example 1
address = "172.16.254.1""IPv4"0..255, and no invalid leading zeros.Example 2
address = "2001:0db8:85a3:0:0:8A2E:0370:7334""IPv6"1 <= len(address) <= 100., :, or other ASCII charactersaddress = "172.16.254.1"Output"IPv4"WhyThere are 4 decimal parts, each is numeric, has no invalid leading zero, and is within the range 0 to 255.address = "2001:0db8:85a3:0:0:8A2E:0370:7334"Output"IPv6"WhyThere are exactly 8 groups, and every group contains 1 to 4 valid hexadecimal characters.address = "256.256.256.256"Output"Neither"WhyEach IPv4 segment must be at most 255, so this address is invalid.1 <= len(address) <= 100IPv4 validation requires exactly 4 segments separated by '.'Each IPv4 segment must be a decimal number in [0, 255] with no leading zeros unless the segment is exactly '0'IPv6 validation requires exactly 8 groups separated by ':'Each IPv6 group must contain 1 to 4 hexadecimal charactersDo not use built-in IP parsing librariesdef validate_ip(address):