Better ipv4/ipv6 addresses extracting and returning