public static bool bConnectToServer() { CSettings.Load(); IPEndPoint RemoteEndPoint = null; tClient = new TcpClient(); try { tClient.Connect(s_WhoisServerAddress, PORT); DataStream = tClient.GetStream(); //DataStream.ReadTimeout = 1000; //DataStream.WriteTimeout = 1000; sSock = tClient.Client; } catch (Exception e) { if (e.Message.Contains("period")) { tClient.EndConnect(_result); } else { throw e; } } return(true); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new frmMain()); CSettings.Load(); }
public static bool bConnectToServer() { CSettings.Load(); //IPEndPoint RemoteEndPoint = new IPEndPoint(IPAddress.Parse(Program.s_WhoisServerAddress), int.Parse(Program.settings.Port)); tClient = new TcpClient(); try { _result = tClient.BeginConnect(Program.s_WhoisServerAddress, int.Parse(Program.settings.Port), null, null); var success = _result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(3)); if (!success) { //Environment.Exit(-1); return(false); } DataStream = tClient.GetStream(); DataStream.ReadTimeout = 1000; DataStream.WriteTimeout = 1000; sSock = tClient.Client; } catch (Exception e) { throw e; } return(true); }
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); } }