public static string GetStatus(bool bSilent = false) { StringBuilder toReturn = new StringBuilder(); Process currentProcess = Process.GetCurrentProcess(); TimeSpan Uptime = DateTime.Now - LaunchTime; TimeSpan TrueProcessorTime = TimeSpan.FromTicks(currentProcess.TotalProcessorTime.Ticks / Environment.ProcessorCount); toReturn.Append("Server status at " + DateTime.Now.ToString("r") + "\r\n"); toReturn.Append(" Server Started: " + LaunchTime.ToString("r") + "\r\n"); toReturn.Append(" Uptime: " + Uptime + "\r\n"); toReturn.Append(" Total CPU Time: " + TrueProcessorTime + " on " + Environment.ProcessorCount + " cores\r\n"); toReturn.Append(" Average CPU Usage: " + (100 * ((TrueProcessorTime.TotalMilliseconds * Environment.ProcessorCount) / Uptime.TotalMilliseconds)) + "%\r\n"); toReturn.Append(" Total RAM Usage: " + (currentProcess.WorkingSet64 / 1024 / 1024) + "MB\r\n"); toReturn.Append(" Thread Pool Info:\r\n"); toReturn.Append(" " + BismuthThreadPool.GetActiveThreadCount() + " active threads\r\n"); toReturn.Append(" " + BismuthThreadPool.GetTotalPossibleThreads() + " free threads\r\n"); toReturn.Append(" " + BismuthThreadPool.GetPendingTaskCount() + " tasks waiting\r\n"); return(toReturn.ToString()); }
private static void Main(string[] args) { var devices = CaptureDeviceList.Instance; if (devices.Count < 1) { Console.WriteLine("No device found on this machine"); return; } Console.WriteLine("The following devices are available on this machine:"); Console.WriteLine("----------------------------------------------------"); Console.WriteLine(); var i = 0; foreach (var dev in devices) { Console.WriteLine("{0}) {1} {2}", i, dev.Name, dev.Description); i++; } Console.WriteLine(); Console.Write("-- Please choose a device to capture: "); i = int.Parse(Console.ReadLine()); var device = devices[i]; device.OnPacketArrival += device_OnPacketArrival; var readTimeoutMilliseconds = 1000; device.Open(DeviceMode.Promiscuous, readTimeoutMilliseconds); var filter = "ip and tcp"; device.Filter = filter; Console.WriteLine(); Console.WriteLine("-- The following tcpdump filter will be applied: \"{0}\"", filter); if (LoginServerIP == null) { Console.Write("-- Please input target LoginServer IP: "); LoginServerIP = IPAddress.Parse(Console.ReadLine()); Console.WriteLine(); } if (LoginServerPort == 0) { Console.Write("-- Please input target LoginServer Port: "); LoginServerPort = int.Parse(Console.ReadLine()); Console.WriteLine(); } BreakIpAddresses.Add(LoginServerIP); ServerPorts.Add(LoginServerPort); Console.WriteLine ("-- Listening on {0}, hit 'Ctrl-C' to exit...", device.Description); var filePath = Path.Combine(LaunchTime.ToString("s").Replace(':', '_'), "PacketFlow.txt"); var flowFile = new FileInfo(filePath); flowFile.Directory?.Create(); using var fs = new FileStream(filePath, FileMode.Create, FileAccess.Write); using (packerFlowStream = new StreamWriter(fs)) { packerFlowStream.AutoFlush = true; device.Capture(); device.Close(); packerFlowStream.Flush(); fs.Flush(true); } }