Usually you should be wary about doing such validations yourself because they tend to be a lot more complicated than it appears on first glance. For example to validate an IPv4 you cannot just check for “4 numbers separated by dots”. You’ll also have to check things like the range of each number (0-255), special cases like 0.0.0.0, etc. Then what about IPv6? URLs/hostnames aren’t any less complex.
To answer your concrete question: No, there is no simple way to validate an IP/hostname.
Either use a dedicated library for checking or simply try to do whatever it is you want to do with the address and handle errors appropriately. You might consider doing a rough sanity check for obvious errors in the beginning, mainly to provide better error messages to the user. But even that requires a bit of thought. For example, it’s easy to forget about IPv6 and reject perfectly valid addresses.