Skip to content

Instantly share code, notes, and snippets.

@XORwell
Created November 12, 2012 06:02
Show Gist options
  • Save XORwell/4057760 to your computer and use it in GitHub Desktop.
Save XORwell/4057760 to your computer and use it in GitHub Desktop.
micro_httpd scanner
import re
import sys
import os
import types
from subprocess import Popen, PIPE
os.system("clear")
# show how it works
def usage():
print "usage: "+ sys.argv[0] +".................."
print "example: "+ sys.argv[0] +" 192.168.1.1"
print "example: "+ sys.argv[0] +" 192.168.1.1-50"
print "example: "+ sys.argv[0] +" 192-195.168.1.1-50"
sys.exit()
# throw and quit
def error_intToBig():
print "error: submitted value bigger than 254"
sys.exit()
# quit if target is missing
if len(sys.argv) <= 1 or len(sys.argv) > 2:
usage()
# get target(s)
ip=sys.argv[1].split('.')
iprange=[]
iplist=[]
# do some checks
for i in range(0,4):
if re.search("-", ip[i]):
val = ip[i].split("-")
if len(val[0]) == 0 or len(val[1]) == 0:
usage()
elif int(val[1]) < int(val[0]):
print "error: %s is smaller than %s" % (val[1], val[0])
sys.exit()
elif int(val[0]) >= 255 or int(val[1]) >= 255:
error_intToBig()
else:
iprange.append( range(int(val[0]), int(val[1])+1) )
else:
if int(ip[i]) >= 255:
error_intToBig()
else:
iprange.append([ip[i]])
# build list of targets
for a in iprange[0]:
for b in iprange[1]:
for c in iprange[2]:
for d in iprange[3]:
iplist.append( str(a)+"."+str(b)+"."+str(c)+"."+str(d) )
# party
print "* Going to scan " + str(len(iplist)) + " hosts."
servers=[]
for host in iplist:
ret = Popen(["curl","-I", host,"--connect-timeout", "1"], stdin=PIPE, stdout=PIPE, stderr=PIPE)
out = ret.communicate()[0]
#match = re.search('Server: \w*', out)
match = re.search('Server: micro_httpd', out)
if match:
servers.append([host, match.group(0)])
print servers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment