Skip to content

Instantly share code, notes, and snippets.

@0atman
Last active August 29, 2015 14:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0atman/2e8434676181ad225b7f to your computer and use it in GitHub Desktop.
Save 0atman/2e8434676181ad225b7f to your computer and use it in GitHub Desktop.
A locally-hosted web page listing all open http servers.
"""
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)
@0atman
Copy link
Author

0atman commented Nov 4, 2014

The is a python implementation of deadlight's idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment