Add ipv6 support, exclude_hosts, and move complex repeated behaviors to functions