Windows2003下面的批量创建随机用户程序(.NET多线程)

翻看以前的代码,发现有这么一个小工具,以前是做了邮件群发服务器的一个工具,现在公布于众把,呵呵,没有多少技术含量,懂的人,觉得太菜了,大家不要吐槽就行。

 

  1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading;
6 using System.Diagnostics;
7 using System.IO;
8
9 namespace CreateMailAddress
10 {
11 class Program
12 {
13 static int count = 10;
14 static string _email_ext = "@mrhuo.com";
15 static int threadID = 0;
16 static int type = 0;
17 static List<string> emailList = new List<string>();
18
19 static void Main(string[] args)
20 {
21 if (args.Length < 1||args.Length<3)
22 {
23 helper("参数个数不正确。");
24 }
25 else
26 {
27 count = Convert.ToInt32(args[1]);
28 _email_ext = "@" + args[0];
29
30 if (args.Length == 3)
31 {
32 type = 0;
33 }
34 else
35 {
36 if (args[3].Remove(0, 1).ToLower() == "test")
37 {
38 type = 0;
39 }
40 else if (args[3].Remove(0, 1).ToLower() == "make")
41 {
42 type = 1;
43 }
44 else
45 {
46 helper("没有 " + args[3].Remove(0, 1) + " 这个参数。");
47 }
48 }
49
50 if (type == 0)
51 {
52 Console.WriteLine("测试创建效果:");
53 }
54 else if (type == 1)
55 {
56 Console.WriteLine("创建邮件地址开始:");
57 }
58 else
59 {
60 helper("错误的参数传递。");
61 }
62
63 while (count > 0)
64 {
65 for (threadID = 1; threadID <= Convert.ToInt32(args[2]); threadID++)
66 {
67 Thread th = new Thread(new ThreadStart(makeMailAddress));
68 th.IsBackground = true;
69 th.Start();
70 th.Join();
71
72 Thread.Sleep(10);
73 }
74 }
75
76 Console.WriteLine("生成 " + args[1] + " 个电子邮件成功!");
77
78 emailList.Sort();
79
80 string _file = string.Empty;
81 foreach (string t in emailList)
82 {
83 _file += t + "\r\n";
84 }
85
86 string filename = "C:\\E_" + DateTime.Now.Ticks.ToString() + ".txt";
87 File.WriteAllText(filename, _file, Encoding.ASCII);
88 Console.WriteLine("邮件地址已经保存到 " + filename + "");
89
90 //Console.ReadLine();
91 }
92 }
93
94 static void makeMailAddress()
95 {
96 try
97 {
98 if (count > 0)
99 {
100 if (type == 0)
101 {
102 Console.WriteLine("线程:" + threadID.ToString() + "启动...");
103 }
104
105 string _email_addr = getRandStr(10) + _email_ext;
106
107 if (type == 1)
108 {
109 ProcessStartInfo pi = new ProcessStartInfo("winpop.exe", "add " + _email_addr + " /createuser \"123456\"");
110 pi.CreateNoWindow = true;
111 pi.WindowStyle = ProcessWindowStyle.Hidden;
112
113 Process.Start(pi);
114 }
115
116 Console.WriteLine("创建用户:" + _email_addr + "成功!");
117
118 emailList.Add(_email_addr + "|123456");
119
120 if (type == 0)
121 {
122 Console.WriteLine("线程:" + threadID.ToString() + "结束...");
123 }
124 count--;
125 }
126 }
127 catch
128 {
129 return;
130 }
131 }
132
133 static string getRandStr(int num)
134 {
135 string _out_trade_no = "";
136
137 string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
138 long tick = DateTime.Now.Ticks;
139 Random rnd = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
140 for (int i = 1; i <= num; i++)
141 {
142 _out_trade_no += chars.Substring(rnd.Next(chars.Length), 1);
143 }
144 //Thread.Sleep(1);
145 return _out_trade_no.ToUpper();
146 }
147
148 static void helper(string err)
149 {
150 Console.WriteLine();
151 Console.WriteLine("错误:" + err + "");
152 Console.WriteLine();
153 Console.WriteLine("介绍:用于随机创建服务器电子邮件地址(For Win2003)。");
154 Console.WriteLine();
155 Console.WriteLine("用法:EmailCreater.exe <mrhuo.com> <1000> <512> [/Test|/Make]");
156 Console.WriteLine(" EmailCreater.exe <邮箱域名> <邮箱个数> <线程> [测试(不生成)|生成(需要服务器的POP服务支持)]");
157 Console.WriteLine();
158 Console.WriteLine(" //Code By QQ:491217650 From:www.mrhuo.com");
159 Console.ReadLine();
160 return;
161 }
162 }
163 }

 

完整的程序下载Demo:
点击下载

转载注明:http://www.mrhuo.comMR.HUO工作室

转载于:https://www.cnblogs.com/MrHuo/archive/2012/02/09/2343658.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值