How to differentiate IP-addresses from domain names during parsing

You should test the user input with regex, just like the ping command does. Below example should match any numeric variation from 0.0.0.0 to 255.255.255.255. Anything that doesn't match should be treated as a domain name.

/^(?=.*[^\.]$)((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.?){4}$/