Template:IsIPAddress

Returns 4 if the address is IPv4, 6 if IPv6, and a blank when not an IP address.