Use IPAddr class to validate ip formats

This fixes #133 and also uses the IPAddr class to validate ipv4.