redis-scan-anonymous

#encoding=utf-8
import socket
import redis
import sys
import re
import argparse

parser = argparse.ArgumentParser()
parser.add_argument("-r",help="-r url.txt",type=str) #命令行参数
parser.add_argument("-t",help="待开发",type=int) #命令行参数
parser.add_argument("-p",help="待开发",type=int) #命令行参数
args = parser.parse_args() #参数位置

txt = str(args.r)

def main():
    f = open(txt, "r")
    lines=f.readlines()
    for url in lines:
        try:
           ip = str(re.findall(r"(.+):", url)[0])
           ports = int(re.findall(r":(.+)", url)[0])
           s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
           s.connect((ip,ports))
           s.close()
           r = redis.StrictRedis(host=ip, port=ports, db=0)
           o = r.info()
           print u"[*]" + ip,str(ports)+ ":", o['os']
        except Exception,msg:
            print u"[-]ip异常:" + ip,ports
        except socket.error,msg:
            print u"[-]ip异常:" + ip,ports
        else:
            pass
    f.close()



if __name__ == '__main__':
    if args.r == None:
        parser.print_help()
    else:
        main()