how to check if variable contains a valid ip address

view story

http://stackoverflow.com – I am writing a shell script program in which I am taking IP address or system name from the user, can anybody tell me how to check if the given IP address or system name is valid. I think ping will not work, I tried it but I can't come out of it, so is there some other method. (HowTos)