Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import optparse
- """Simple portscan, HackForLulz"""
- def portscan(h, p, options):
- try:
- conn = socket.socket("AF_INET", "SOCK_STREAM")
- if options.timeout is None:
- conn.setdefaulttimeout(3)
- else:
- conn.setdefaulttimeout(options.timeout)
- conn.connect((h.rstrip(), int(p)))
- print "[+] %d port open" % int(p)
- except:
- print "[-] %d port closed" % int(p)
- def scanfile(options,b):
- for x in b.readlines():
- if x=="\n":
- continue
- try:
- h = socket.gethostbyname(x.rstrip())
- except:
- print "[-] Cannot resolve %s : Unknown host" %x.rstrip()
- continue
- p = (options.port).split(",")
- print "[+] Scan %s :"%x.rstrip()
- socket.setdefaulttimeout(2)
- for y in p:
- print "[+] Scanning port ",y
- portscan(x,y,options)
- print "\n"
- def scan(options):
- try:
- h = socket.gethostbyname(options.host)
- except:
- print "[-] Cannot resolve %s : Unknown host" % h
- return
- p = (options.port).split(",")
- print "[+] Scan %s\n" % h
- socket.setdefaulttimeout(2)
- for x in p:
- print "[+] Scanning port ", x
- portscan(h, x, options)
- print "\n"
- def main():
- p = optparse.OptionParser("usage %prog -H <host> -p <port> [-F <file>]")
- p.add_option("-H", "--host", dest="host", type="string", help="target host")
- p.add_option("-p", "--port", dest="port", type="string", help="target port")
- p.add_option("-f", "--file", dest="file", type="string",help="target file")
- p.add_option("-t", "--timeout", dest="timeout", type="int",help="timeout in second (default 3s)")
- (options,args) = p.parse_args()
- if(options.host is None and options.file is None):
- return
- elif(options.port is None):
- return
- elif(options.host is not None and options.file is not None):
- return
- elif(options.file is not None):
- b=open(options.file,"r")
- scanfile(options,b)
- else:
- scan(options)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment