Example #1
0
        static void Main(string[] args)
        {
            CSettings.Load();
            if (args.Length == 0)
            {
                gui = true;
                ShowWindow(Process.GetCurrentProcess().MainWindowHandle, 0);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new frmMain());
            }
            else
            {
                AllocConsole();

                List <string> largs = args.ToList <string>();
                //try
                //{
                if (args.Length > 2)
                {
                    int       hIndex = 0, pIndex = 0, gIndex = 0;
                    IPAddress nIp = IPAddress.Any;
                    foreach (string s in args)
                    {
                        if (s == "localhost")
                        {
                            hIndex               = gIndex;
                            settings.IPAddress   = IPAddress.Parse("127.0.0.1").ToString();
                            s_WhoisServerAddress = IPAddress.Parse("127.0.0.1").ToString();
                            largs.Remove(largs.Where(T => T == "-h").FirstOrDefault());
                            largs.Remove(s);
                            continue;
                        }
                        if (s == "-h")
                        {
                            s_WhoisServerAddress = args[args.ToList().IndexOf("-h") + 1];
                        }
                        //s_WhoisServerAddress = args[gIndex+1];
                        foreach (string ss in largs)
                        {
                            args.ToList().Remove(ss);
                        }
                        if (IPAddress.TryParse(args[hIndex], out nIp))
                        {
                            if (!args[hIndex].Contains('.'))
                            {
                                continue;
                            }
                            settings.IPAddress   = args[hIndex - 1];
                            s_WhoisServerAddress = args[hIndex - 1];
                            largs.Remove(largs.Where(T => T == "-h").FirstOrDefault());
                            if (largs[0].Contains('.'))
                            {
                                largs.RemoveAt(0);
                            }

                            break;
                        }
                        if (largs.Contains("-p") && int.TryParse(args[args.ToList().IndexOf("-p") + 1], out PORT))
                        {
                            settings.Port = PORT.ToString();
                            largs.Remove(largs.Where(T => T == "-p").FirstOrDefault());
                            largs.Remove(s);
                        }
                        gIndex++;
                    }
                }

                Program.settings.Protocol = Protocols.WHOIS;
                if (args.Contains("-h1"))
                {
                    Program.settings.Protocol = Protocols.HTTP11;
                }
                if (args.Contains("-h0"))
                {
                    Program.settings.Protocol = Protocols.HTTP10;
                }
                if (args.Contains("-h9"))
                {
                    Program.settings.Protocol = Protocols.HTTP09;
                }
                largs.Remove("-h1");
                largs.Remove("-h0");
                largs.Remove("-h9");
                largs.Remove("-h");
                largs.Remove("-p");
                largs.Remove(settings.Port);
                largs.Remove(s_WhoisServerAddress);

                string loc = "";
                if (largs.Count >= 2)
                {
                    for (int i = 1; i < largs.Count; i++)
                    {
                        loc += (largs[i] + ' ');
                    }
                }
                foreach (string s in loc.Split(' '))
                {
                    largs.Remove(s);
                }
                //if (loc != "")
                //    largs.Add(loc);

                //setup request

                KNetwork networktools = new KNetwork();

                networktools.SendMessage(largs[0], loc, Program.settings.Protocol);
            }
        }