Last active
January 24, 2019 09:26
-
-
Save vijay922/f6fbb1471d83c55f7181f647ccaae1e9 to your computer and use it in GitHub Desktop.
Domain 2 IP in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python | |
import os | |
import sys | |
import datetime | |
import os.path | |
if len(sys.argv)!=3: | |
print "This script takes two file \n 1. InputFile with hostnames \n 2. OutputFilename \n\n Example: python domain_2_ip.py [INPUT_FILE_NAME] [OUTPUT_FILE_NAME]" | |
else: | |
if os.path.exists(sys.argv[1]): | |
print ('Initiating...\n') | |
input = open(sys.argv[1], 'r').read().split('\n') | |
temp_file = str(datetime.datetime.now().time())+'.txt' | |
for domain_name in input[:-1]: | |
cmd = 'host ' + domain_name + ' | grep "has address" | cut -d " " -f 4 >>'+temp_file | |
os.system(cmd) | |
sort_output = 'cat ' + temp_file +' | sort | uniq > '+ sys.argv[2] | |
os.system(sort_output) | |
print 'Done! Check file : '+sys.argv[2] | |
else: | |
print "\nInput File Doesn't Exists !!!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment