This works for IPv4 addresses but not IPv6

I only needed IPv4 for now but I will try to get back to this in the future.