This packs a lot of conditionals into a single line which makes it hard to read and to test. 

Instead of `(IPAddr.new(tmp) rescue nil).nil?` you could use [validate_ip_addr](http://netaddr.rubyforge.org/classes/NetAddr.html#M000013) to ensure that the IP address is valid

In terms of making the conditional more readable, it might be better to break it up into multiple lines and use something like a case statement.