#!/usr/bin/env python
#####################
#-----------------------------------------------+
#                      ._____________________.  |
#   coded by slav0nic  | slav0nic0@gmail.com |  |    
#                      ^---------------------^  |
# site: slav0nic.xss.ru                         |
#-----------------------------------------------+
import sys
import getopt
import time
import os

start=time.clock()  
#@@@@@@@@__Defaul__@@@@@@@@@@@@@@@@@@@
first_uin=10000
last_uin=20000
step=1
coma=';'
output_file='list.txt'
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
HELP="""
 -h --help          print help
 -v --version       print version
 -f --first_uin     define first UIN
 -e --last_uin      define last UIN
 -s --step          step for UINs generate
 -c --coma          coma between UIN-Password
                    -c without parameters-> coma=' '
 -p --password      define static password 
 -P --pass-list     define file whith passwords
                    (one password in line)
 -o --output        output file
"""
VERSION='PyUIN_Pass_v1.0'
password_list=[]

try:
    opts, args = getopt.getopt(sys.argv[1:],'hvf:l:s:c:c:p:P:o:',\
                ['help','version','first_uin=','last_uin=','step=','coma=','coma','password=','pass-list=','output='])
except getopt.GetoptError:
    print HELP
    sys.exit()
        
for o, a in opts:
    if o in ('-h', '--help'):
        print HELP
        sys.exit()
    if o in ('-v', '--version'):
        print '\n\t',VERSION
        sys.exit()
        
    if o in ('-f','--first_uin'):
        try:
            first_uin=int(a)
        except:
            print "[-]First_UIN %s not integer" %a
            sys.exit(1)
    if o in ('-l','--last_uin'):
        try:
            last_uin=int(a)
        except:
            print "[-]Last_UIN %s not integer" %a
            sys.exit(1)
    if o in ('-s','--step'):
        try:
            step=int(a)
        except:
            print "[-]Step %s not integer" %a
            sys.exit(1)
    if o in ('-c','--coma'):
        if not a:
            coma=' '
        else:
            coma=str(a)
    if o in ('-p','--password'):
        password_list.append(a)
        print password_list
    if o in ('-P','--pass-list'):
        try:
            fd=open(a,'r')
        except:
            print "[-]Can't open password_list: %s"%a
            sys.exit(1)
        while 1:
            line=fd.readline()
            if not line: break
            password_list.append(line.split('\n')[0]) #delete '\n'
        fd.close()
        
    if o in ('-o','--output'):
        output_file=a
                 
#---------------------------------------------------#            
print "Configuration:\n\tfirst_uin= %i\n\tlast_uin= %i\n\tstep= %i\n\tcoma= %s\n\toutput_file= %s\n\tloaded_passwords= %i\n"\
      %(first_uin,last_uin,step,coma,output_file,len(password_list))
try:
    fd=open(output_file,'w')
except:
    print "[-]Can't open %s" %output_file
    sys.exit(1)
for i in range(first_uin,last_uin,step):
    for j in range(len(password_list)):
        x=str(i)+coma+password_list[j]+'\n'
        fd.write(x)
        
fd.close()

print 'Output_file size ~ %d Kb' % (len(open(output_file).read()) / 1024)
print 'Time %f s'%(time.clock()-start)
print '[+]OK'





