Is there a function in Python that determines if a hostname is a domain name or an IP (v4) address?
Note. The domain name may look like alex.foo.bar.com or even (I think it is really) 1.2.3.com .
alex.foo.bar.com
1.2.3.com
I would use IPy to check if a string is an IP address, and if not, let's say it's a domain name. For example:.
from IPy import IP def isIP(str): try: IP(str) except ValueError: return False return True