@@ -0,0 +1,1256 @@
+#!/usr/bin/env python%0Aimport socket%0Aimport sys%0A%0A%22%22%22%09%0A%09listhosts, a simple Python command line utility%0A%09%0A%09Prints the host addresses of each domain listed in a file%0A%09%0A%09Author: Janne Ahlberg%0A%09%0A%09Revision history%0A%09- 12-Jul-2014%09%09first revision%0A%09%0A%22%22%22%0A%0Aclass ListHosts:%0A%09%22%22%22 ListHosts class %22%22%22%0A%09domains = %5B%5D%0A%09%0A%09def read_domains(self, file_name):%0A%09%09%22%22%22 read domain names from a text file %0A%09%09%22%22%22%0A%09%09try:%0A%09%09%09text_file = open(file_name, %22r%22)%0A%09%09except:%0A%09%09%09print %22Failed to open input file %25s%22 %25 (file_name)%0A%09%09%09exit(1)%0A%09%09self.domains = text_file.readlines()%0A%09%09text_file.close()%0A%0A%09def print_hosts(self):%0A%09%09%22%22%22 gets the host address for each domain and prints it %0A%09%09%22%22%22%0A%09%09text_out = %22%25s has address: %25s%22%0A%09%0A%09%09for domain in self.domains:%0A%09%09%09domain = domain.strip()%0A%09%09%09try:%0A%09%09%09%09ip_number = socket.gethostbyname(domain)%0A%09%09%09except:%0A%09%09%09%09ip_number = %22failed!%22%0A%09%09%0A%09%09%09print text_out %25 (domain, ip_number)%0A%0Aclass Main:%0A%09%22%22%22 Main class - similar to main() function in C %22%22%22%0A%09def usage(self):%0A%09%09print %22Usage: python listhosts.py filename%22%0A%09%09%0A%09def __init__(self, argv):%0A%09%09%22%22%22 init function%0A%09%09%22%22%22%0A%09%09try:%0A%09%09%09file_name = argv%5B0%5D%0A%09%09except:%0A%09%09%09self.usage()%0A%09%09%09exit(1)%0A%09%09%0A%09%09x = ListHosts()%0A%09%09x.read_domains(file_name)%0A%09%09x.print_hosts()%0A%09%09%0Aif __name__ == %22__main__%22:%0A%09x = Main(sys.argv%5B1:%5D)%0A

Create listhosts.py