1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| #coding=utf-8
import optparse import random
parse = optparse.OptionParser(usage="usage:%parse [option] -n [number]",version="1.1") #用optparse库设置参数 parse.add_option('-n',dest='number',type=int,help='Student station number') parse.add_option('-i',dest='ip_addr',type=str,help='IP ADDRESS') options,args=parse.parse_args() print 'If you want to see the help Handbook -h'
def ip2num(ip): #ip地方范围 ips = [int(x) for x in ip.split('.')] return ips[0]<< 24 | ips[1]<< 16 | ips[2] << 8 | ips[3] def num2ip (num): return '%s.%s.%s.%s' % ((num >> 24) & 0xff, (num >> 16) & 0xff, (num >> 8) & 0xff, (num & 0xff)) #return '%s.%s.%s.%s' % ((num & 0xff000000)>>24,(num & 0x00ff0000)>>16,(num & 0x00000ff00)>>8,num & 0x000000ff) def gen_ip(ip): start ,end = [ip2num(x) for x in ip.split('-')] return [num2ip(num) for num in range(start,end+1) if num & 0xff] Ip = gen_ip(options.ip_addr)
opt_num = options.number + 1
for g_number in range(1,opt_num): def salt(num): ws_id = "ws" + str(g_number) for salt_num in range(num): str_int = "qwertyuiopasdfghjkzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM" #随机生成8位密码 sa = [] for i in range(8): sa.append(random.choice(str_int)) salt = ''.join(sa) test1 = "%s,%d,%s,%s,%s" % (ws_id,g_number,ws_id,salt,Ip[g_number-1])
print test1
a = open('/Users/fidcer/Documents/ws2018/ws2018.csv','a') a.write("%s\r\n"%test1 ) a.close() salt_number = salt(1)
#ip_dest = IPy.IP("%s" % str(options.ip_addr)) # 生成ip #for ip_ADDR in ip_dest: # print ip_ADDR
|