Last active
August 29, 2015 14:08
-
-
Save 0atman/2e8434676181ad225b7f to your computer and use it in GitHub Desktop.
A locally-hosted web page listing all open http servers.
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
""" | |
A locally-hosted web page listing all open http servers. | |
Requirements: | |
nmap (apt-get install nmap) | |
sh, werkzeug (pip install sh, werkzeug) | |
""" | |
from werkzeug.wrappers import Request, Response | |
from sh import nmap | |
print " * Running nmap..." | |
output = nmap("localhost", A=True, T=5) | |
print " * nmap complete, restart server to refresh port list." | |
@Request.application | |
def application(request): | |
template = "<li><a href=\"http://" + \ | |
request.host_url.split('/')[2].split(':')[0] + \ | |
":%s\">%s</a></li>" | |
pages = {} | |
stripped_output = [ | |
o for o in output.splitlines() | |
if "http" in o.split() or "|_http-title:" in o.split() | |
] | |
print stripped_output | |
for en in enumerate(stripped_output): | |
if "http" in en[1].split(): | |
pages[en[1].split('/')[0]] = \ | |
stripped_output[en[0]+1].split(': ')[1] | |
return Response( | |
"<html><head></head><body><h1>Local Servers</h1>" + | |
"".join(map(lambda p: template % (p, pages[p]), pages.keys())) + | |
"</body></html>", | |
mimetype='text/html' | |
) | |
if __name__ == '__main__': | |
from werkzeug.serving import run_simple | |
run_simple('0.0.0.0', 4000, application) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The is a python implementation of deadlight's idea.