Skip to content

Instantly share code, notes, and snippets.

@ao
Last active October 26, 2016 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ao/0d0c35a75498d2fc88aee300f379ab98 to your computer and use it in GitHub Desktop.
Save ao/0d0c35a75498d2fc88aee300f379ab98 to your computer and use it in GitHub Desktop.
Python: Identify/Get the hosting Server from a list of domain names (commandline)
import sys
import requests
import random
from multiprocessing.dummy import Pool as ThreadPool
'''
Usage:
$ python server.py random 25
$ python server.py google.com
$ python server.py google.com facebook.com whatsapp.com
'''
def test(url):
try:
r = requests.get(url, allow_redirects=True)
if r.status_code==200:
server = r.headers.get('Server')
if server:
print url+": "+server
else:
print url+": Unknown"
else:
# print "!200"
pass
except:
pass
def generateDomainName(amount=5):
word_site = "http://svnweb.freebsd.org/csrg/share/dict/words?view=co&content-type=text/plain"
response = requests.get(word_site)
WORDS = response.content.splitlines()
random.shuffle(WORDS)
words_out = ["http://"+ s + ".com" for s in WORDS[:int(amount)]]
return words_out
if __name__=="__main__":
if len(sys.argv)>1:
if sys.argv[1]=='random':
if len(sys.argv)==3: amount=int(sys.argv[2])
else: amount=5
pool = ThreadPool(10)
randomList = generateDomainName(amount)
results = pool.map(test, randomList)
# for domain in randomList:
# test('http://'+domain)
pool.close()
pool.join()
else:
for domain in (sys.argv[1:]):
test('http://'+domain)
else:
print "specify at least 1 domain name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment