static void Main(string[] args)
        {
            //Console.SetOut(new CustomTextWriter(Console.Out));
            logger.Info("Usage: <staring port> [<proxy count(not used)> | range-check]");

            Config = MyConfig.Load();

            //IMbnInterfaceManager interfaceManager = (IMbnInterfaceManager)new MbnInterfaceManager();
            //InterfaceManager = interfaceManager;

            int staringPort = Int32.Parse(args[0]);

            logger.Info($"Listening start port: {staringPort}");

            if (args.Length >= 2 && args[1] == "range-check")
            {
                IPRangeTest = true;
            }

            //int proxyCount = Int32.Parse(args[1]);
            //Console.WriteLine("Starting {0} Proxies", proxyCount);

            nextID = staringPort + 1;

            //for (int n = 0; n < proxyCount; ++n)
            //{
            //    quadplayProxyList.Add(new QuadplayProxy(nextID++));
            //}

            screenEnabled = !File.Exists("screen_off");

            RefreshRunningProxies();
            RunServer(staringPort);

            new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        RefreshRunningProxies();
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                    }

                    Thread.Sleep(5000);
                }
            })
            {
                Name = "RefreshInterfaces",
            }.Start();

            while (true)
            {
                lock (proxiesToChangeIP)
                {
                    for (int n = proxiesToChangeIP.Count - 1; n >= 0; --n)
                    {
                        try
                        {
                            QuadplayProxy qproxy = null;

                            lock (quadplayProxyList)
                            {
                                foreach (var qp in quadplayProxyList)
                                {
                                    if (qp.ID == proxiesToChangeIP[n])
                                    {
                                        qproxy = qp;
                                        break;
                                    }
                                }
                            }

                            proxiesToChangeIP.RemoveAt(n);

                            if (qproxy != null)
                            {
                                qproxy.ChangeIP();
                            }
                        }
                        catch (Exception e)
                        {
                            logger.Error(e);
                        }
                    }
                }

                Thread.Sleep(50);
            }
        }
        static void RefreshRunningProxies()
        {
            List <string> infIdList = new List <string>();

            IMbnInterfaceManager interfaceManager = null;

            try
            {
                interfaceManager = (IMbnInterfaceManager) new MbnInterfaceManager();

                foreach (var obj in interfaceManager.GetInterfaces())
                {
                    try
                    {
                        IMbnInterface inf = (IMbnInterface)obj;
                        infIdList.Add(inf.InterfaceID);
                        Marshal.FinalReleaseComObject(inf);
                    }
                    catch { }
                }
            }
            finally
            {
                if (interfaceManager != null)
                {
                    Marshal.FinalReleaseComObject(interfaceManager);
                }
            }

            foreach (var qproxy in quadplayProxyList)
            {
                if (!infIdList.Contains(qproxy.InterfaceID))
                {
                    qproxy.InvalidateInterface();
                }
            }

            foreach (string infId in infIdList)
            {
                bool exists = false;

                foreach (var qproxy in quadplayProxyList)
                {
                    if (qproxy.InterfaceID == infId)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    bool added = false;

                    lock (quadplayProxyList)
                    {
                        foreach (var qproxy in quadplayProxyList.OrderBy(el => random.Next()))
                        {
                            if (qproxy.InterfaceID == null)
                            {
                                qproxy.SetToInterface(infId);
                                logger.Info($"Binded Proxy: {qproxy.ID} To Interface: {qproxy.InterfaceID}");
                                added = true;
                                break;
                            }
                        }
                    }

                    if (!added)
                    {
                        var qproxy = new QuadplayProxy(nextID++);
                        qproxy.SetToInterface(infId);
                        qproxy.Start();

                        lock (quadplayProxyList)
                        {
                            quadplayProxyList.Add(qproxy);
                        }
                    }
                }
            }
        }