You don't want to use the ping command, but you can use Python's socket.gethostbyname()
function to determine whether a host exists.
def is_valid_host(hostname):
try:
addr = socket.gethostbyname(hostname)
except socket.gaierror, ex:
return False
return True
hosts = ['abc', 'yahoo.com', 'google.com', 'nosuchagency.gov']
filter(is_valid_host, hosts)
This is going to take tons of time and maybe make your ISP mad at you. You're better off either:
Using a lower-level DNS interface such as dnspython, or
Finding a direct interface to domain registrars, such as whois, and querying that.
You aren't going to use this to spam people, are you?