static int Main(string[] args) { Opts opts; if (!Opts.ParseOpts(args, out opts)) { return(4); } _packages = 0; UdpRacerServer.Start(opts.Port, 16); Console.WriteLine($"listening on port: {opts.Port}"); if (opts.IPs != null && opts.IPs.Count > 0) { Console.WriteLine($"IPs parsed: {String.Join(";",opts.IPs)}"); byte[] initialPacket = UdpRacerStart.CreateNetworkPackage(opts.IPs, opts.Port); Console.WriteLine("++++ UDP package"); UdpRacerStart.PrintUdpRacerPackage(initialPacket); Console.WriteLine("++++ UDP package"); using (UdpClient udpc = new UdpClient()) { var sendTo = new IPEndPoint(opts.IPs[0], opts.Port); udpc.Send( initialPacket, initialPacket.Length, sendTo); Console.WriteLine($"sent initial package to: {sendTo}"); } } ManualResetEvent ended = new ManualResetEvent(false); while (!ended.WaitOne(1000)) { long pkgPerSec = Interlocked.Exchange(ref _packages, 0); Console.WriteLine($"{pkgPerSec}"); } return(0); }
public static bool ParseOpts(string[] args, out Opts opts) { opts = null; bool showhelp = false; string IPList = null; Opts tmpOpts = new Opts() { Port = 4444 }; var cmdOpts = new BeeOptsBuilder() .Add('p', "port", OPTTYPE.VALUE, "udp port to listen", o => tmpOpts.Port = Convert.ToUInt16(o)) .Add('i', "ip", OPTTYPE.VALUE, "ips for packet to inject", o => IPList = o) .Add('h', "help", OPTTYPE.BOOL, "show help", o => showhelp = true) .GetOpts(); var IPsString = Spi.BeeOpts.Parse(args, cmdOpts, (string unknownOpt) => Console.Error.WriteLine($"unknow option [{unknownOpt}]")); if (showhelp) { Spi.BeeOpts.PrintOptions(cmdOpts); Console.WriteLine( "\nSample:" + "UdpRacer.exe -i 10.2.2.2,10.1.1.1" ); return(false); } if (!String.IsNullOrEmpty(IPList)) { if (!TryParseIPs( IpsAsString: IPList.Split(',').Select(i => i.Trim()), IPs: out tmpOpts.IPs)) { return(false); } } opts = tmpOpts; return(true); }