public static void Run() { object console = new object(); Dictionary <string, EthAddress> list = new Dictionary <string, EthAddress>(); Action a = () => { Random r = new Random(); while (list.Count != ushort.MaxValue) { byte[] privKey = new byte[32]; r.NextBytes(privKey); EthAddress e = new EthAddress(privKey); string sub = e.Address.Substring(0, 2) + e.Address.Substring(e.Address.Length - 2, 2); lock (list) { if (list.ContainsKey(sub)) { continue; } list.Add(sub, e); } lock (console) { Console.ForegroundColor = ConsoleColor.White; Console.Write(e.PrivateKey.ToHex()); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" [" + e.Address + "]"); Console.Title = list.Count.ToString(); } } }; Task ta = new Task(a), tb = new Task(a), tc = new Task(a); ta.Start(); tb.Start(); tc.Start(); Task.WaitAll(ta, tb, tc); File.WriteAllLines ( ".\\Keys.txt", list.Values .OrderBy(u => u.Address) .Select(u => u.PrivateKey.ToHex() + " [" + u.Address + "]") ); File.WriteAllLines ( ".\\Addresses.txt", list.Values .Select(u => u.Address) .OrderBy(u => u) ); }
//Generate New Ethereum Address public EthAddress GenerateEthAddress() { EthAddress eta = new EthAddress(); var ecKey = Nethereum.Signer.EthECKey.GenerateKey(); var privateKey = ecKey.GetPrivateKeyAsBytes().ToHex(); var account = new Account(privateKey); eta.EthPublicKey = account.Address; eta.EthPrivateKey = privateKey; return(eta); }
public static void Run() { Console.WriteLine("Press Control+C for cancel"); Console.CancelKeyPress += Console_CancelKeyPress; object console = new object(); ConnectionOptions connectionOptions = new ConnectionOptions() { Port = "8545", Url = "http://127.0.0.1" }; long have = 0; Random r = new Random(); EthereumService ethereumService = new EthereumService(connectionOptions); while (!Cancel) { Parallel.For(0, 1000, (i) => { if (Cancel) { return; } byte[] privKey = new byte[32]; r.NextBytes(privKey); EthAddress e = new EthAddress(privKey); string endAddress = e.Address; if (!endAddress.StartsWith("0x")) { endAddress = "0x" + endAddress; } string sammout; try { //Thread.Sleep(5); Interlocked.Increment(ref have); long tx = ethereumService.GetTransactionCount(endAddress, BlockTag.Latest); if (tx == 0) { return; } BigInteger ammout = ethereumService.GetBalance(endAddress, BlockTag.Latest); sammout = ammout.ToString(); } catch (Exception ex) { sammout = "ERROR " + ex.Message; } finally { lock (console) Console.Title = have.ToString(); } lock (console) { Console.ForegroundColor = ConsoleColor.White; Console.Write("[" + privKey.ToHex() + "] "); Console.ForegroundColor = sammout.StartsWith("ERROR ") ? ConsoleColor.Red : ConsoleColor.Yellow; Console.WriteLine(sammout); File.AppendAllText("./Lotery.txt", privKey.ToHex() + " " + sammout + Environment.NewLine); } }); } }