public static void PacketCounter() { Console.WriteLine("Counter started..."); while (true) { Thread.Sleep(100); foreach (int count in hwCount.ToList()) { if (count > 20) { if (!hasAlerted) { Console.WriteLine("\nWARNING"); Console.WriteLine("\t" + hwList[hwCount.IndexOf(count)] + " seems to be attempting to wipe the network cache."); Console.WriteLine("\tHas " + count + " packets sent with same hardware address"); Console.WriteLine("Flushing and Freezing..."); int id = AdapterController.GetAdapterId(adapterId); string gateway = AdapterController.GetGateway(); CacheController.FlushFreezeArp(id, AdapterController.GetGateway()); hasAlerted = true; Console.WriteLine(); } } } } }
public DebugAdapter(Type mmuType, int hostingPort = 8999, string registerAddress = "127.0.0.1", int registerPort = 9009) { RegisterAddress = new MIPAddress(registerAddress, registerPort); //Create a new logger instance Logger.Instance = new Logger { //Log everything Level = Log_level.L_DEBUG }; MAdapterDescription adapterDescription = new MAdapterDescription() { ID = Guid.NewGuid().ToString(), Language = "C#", Name = "Debug Adapter C#", Properties = new Dictionary <string, string>(), Addresses = new List <MIPAddress>() { new MIPAddress("127.0.0.1", hostingPort) } }; adapterController = new AdapterController(SessionData, adapterDescription, RegisterAddress, new MMUProvider(mmuType), new MMUInstantiator(mmuType)); adapterController.StartAsync(); }
public NetworkMonitor(AdapterController adapterC) { this.adapter = adapterC; InitAdapter(); monitor = new Timer(); monitor.Interval = 1000; monitor.Elapsed += Monitor_Elapsed; }
static void Main(string[] args) { s_AdapterController = new AdapterController <HGUPBossAsynAdapter>(); s_AdapterController.Prepare(); Console.WriteLine(s_AdapterController.Adapter.Name + " 已经启动, 等待控制器命令..."); while (true) { Thread.Sleep(Timeout.Infinite); } }
static void Main(string[] args) { controller = new AdapterController <HGU_HuaWei_Adapter>(); controller.Prepare();//核心入口 controller.Start(); //Console.WriteLine(controller.Adapter.Name + " 已经启动, 等待控制器命令..."); while (true) { Thread.Sleep(Timeout.Infinite); } }
static void Main(string[] args) { s_AdapterController = new AdapterController <HGU_Bell_Adapter>(); //为采集器赋值 s_AdapterController.Prepare(); //正式运行时,是通过其他进程来发送命令的方式来启动采集进程的,而调试时,必须主动启动采集进程才可能出现窗口 //s_AdapterController.Start();//调试时取消注释,显示程序运行窗口,正式运行时应将其注释 Console.WriteLine(s_AdapterController.Adapter.Name + " 已经启动, 等待控制器命令..."); while (true) { Thread.Sleep(Timeout.Infinite); } }
static void Main(string[] args) { Console.WriteLine(@" ______ _____ _ __ __ _ "); Console.WriteLine(@" / ____/___ / ___/(_)___ ___ __ __/ /___ _/ /_(_)___ ____ "); Console.WriteLine(@" / / / __ \______\__ \/ / __ `__ \/ / / / / __ `/ __/ / __ \/ __ \"); Console.WriteLine(@"/ /___/ /_/ /_____/__/ / / / / / / / /_/ / / /_/ / /_/ / /_/ / / / /"); Console.WriteLine(@"\____/\____/ /____/_/_/ /_/ /_/\__,_/_/\__,_/\__/_/\____/_/ /_/ "); Data.SessionData = new SessionData(); //Create a new adapter controller using (AdapterController adapterController = new AdapterController(Data.SessionData, Data.AdapterDescription, new MIPAddress("127.0.0.1", 9009), new DescriptionBasedMMUProvider(Data.CoSimMMUDescription), new CosimInstantiator())) { adapterController.Start(); Console.ReadLine(); } }
private void ApplyConfig() { try { switch (Settings.EnableMonitoring) { case true: // Configure format Format = configuration.Format; // Initialize adapter adapterController = new AdapterController(configuration.MonitoredAdapter); monitor = new NetworkMonitor(adapterController); // Start Monitoring monitor.Start(); switch (Format) { case "Auto": timerAuto.Start(); break; case "KB": timerKB.Start(); break; case "MB": timerMB.Start(); break; } break; case false: LblUpload.Text = "N/A"; LblDownload.Text = "N/A"; break; } } catch (Exception ex) { LblUpload.Text = "N/A"; LblDownload.Text = "N/A"; } }
private void Load_Config() { try { configuration = registryManager.GetGeneralConfiguration(); if (configuration.Monitoring == true) { Format = configuration.Format; adapterController = new AdapterController(configuration.MonitoredAdapter); monitor = new NetworkMonitor(adapterController); monitor.Start(); switch (Format) { case "Auto": timerAuto.Start(); break; case "KB": timerKB.Start(); break; case "MB": timerMB.Start(); break; } } else { LblUpload.Text = "N/A"; LblDownload.Text = "N/A"; } } catch (Exception ex) { LblUpload.Text = "N/A"; LblDownload.Text = "N/A"; } }
static void Main(string[] args) { MAdapterDescription adapterDescription = new MAdapterDescription() { ID = Guid.NewGuid().ToString(), Language = "C#", Name = "Debug Adapter C#", Properties = new Dictionary <string, string>(), Addresses = new List <MIPAddress>() { new MIPAddress("127.0.0.1", 8999) } }; using (AdapterController adapterController = new AdapterController(SessionData, adapterDescription, RegisterAddress, new MMUProvider(), new MMUInstantiator())) { adapterController.Start(); Console.ReadLine(); } }
static void Main(string[] args) { // New cache controller. byte[] router = CacheController.GetCachedAddress("10.0.0.1"); Console.WriteLine(AdapterController.GetGateway()); // Make sure we got something. // Byte array length should be the same as a mac address length in bytes. if (router != null) { Console.WriteLine(BytesToString(router)); } else { Console.WriteLine("Router has no cached address?"); } // Get device list from local machine IList <LivePacketDevice> allDevices; try { allDevices = LivePacketDevice.AllLocalMachine; } catch (InvalidOperationException e) { Console.WriteLine(e.Message); allDevices = new List <LivePacketDevice>(); } if (allDevices.Count == 0) { Console.WriteLine("No interfaces found. Make sure libpcap/WinPcap is properly installed on the local machine."); return; } // Print the list Console.WriteLine("\nInterface Device List:"); for (int i = 0; i != allDevices.Count; i++) { LivePacketDevice device = allDevices[i]; Console.Write((i + 1) + ". " + device.Name + " " + string.Join(", ", device.Addresses)); if (args.Length > 0) { if (args[0] == "-d") { DevicePrint(allDevices[i]); } } if (device.Description != null) { Console.WriteLine(" (" + device.Description + ")"); } else { Console.WriteLine(" (No description available)"); } } int deviceIndex = 0; do { Console.WriteLine("Enter the interface number (1-" + allDevices.Count + "):"); string deviceIndexString = Console.ReadLine(); if (!int.TryParse(deviceIndexString, out deviceIndex) || deviceIndex < 1 || deviceIndex > allDevices.Count) { deviceIndex = 0; } } while (deviceIndex == 0); ThreadStart childref = new ThreadStart(PacketCounter); Console.WriteLine("In Main: Creating the Child thread"); Thread childThread = new Thread(childref); childThread.Start(); // Take the selected adapter PacketDevice selectedDevice = allDevices[deviceIndex - 1]; adapterId = selectedDevice.Name.Split('_')[1]; // open the device using (PacketCommunicator communicator = selectedDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000)) { Console.WriteLine("Listening on " + selectedDevice.Description + "..."); // Start the capture communicator.SetFilter("arp"); communicator.ReceivePackets(0, PacketHandlerArp); } }
/// <summary> /// Entry routine /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Create a new logger instance Logger.Instance = new Logger { //Log everything Level = Log_level.L_DEBUG }; //Register for unhandled exceptions in the application AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Console.WriteLine(@" ______ __ __ ___ __ __ "); Console.WriteLine(@" / ____/_/ // /_ / | ____/ /___ _____ / /____ _____"); Console.WriteLine(@" / / /_ _ __/ / /| |/ __ / __ `/ __ \/ __/ _ \/ ___/"); Console.WriteLine(@"/ /___/_ _ __/ / ___ / /_/ / /_/ / /_/ / /_/ __/ / "); Console.WriteLine(@"\____/ /_//_/ /_/ |_\__,_/\__,_/ .___/\__/\___/_/ "); Console.WriteLine(@" /_/ "); Console.WriteLine(@"_________________________________________________________________"); //Parse the command line arguments if (!ParseCommandLineArguments(args)) { Logger.Log(Log_level.L_ERROR, "Cannot parse the command line arguments. Closing the adapter!"); return; } Console.WriteLine($"Adapter is reachable at: {address.Address}:{address.Port}"); Console.WriteLine($"Register is reachable at: {mmiRegisterAddress.Address}:{mmiRegisterAddress.Port}"); Console.WriteLine($"MMUs will be loaded from: {mmuPath}"); Console.WriteLine(@"_________________________________________________________________"); //Create the adapter description -> To do load from file in future MAdapterDescription adapterDescription = new MAdapterDescription() { Name = "CSharpAdapter", Addresses = new List <MIPAddress>() { address }, ID = "438543643-436436435-2354235", Language = "C#", Parameters = new List <MParameter>(), Properties = new Dictionary <string, string>() }; //Create a session cleaner for the utilized session data sessionCleaner = new SessionCleaner(sessionData) { //Session shoould be cleaned after 60 minutes Timeout = TimeSpan.FromMinutes(60), //The session cleaner should check every minute UpdateTime = TimeSpan.FromMinutes(1) }; //Start the session cleaner sessionCleaner.Start(); //Create a new adapter controller which scans the filesystem and checks for MMUs there using (AdapterController adapterController = new AdapterController(sessionData, adapterDescription, mmiRegisterAddress, new FileBasedMMUProvider(sessionData, new List <string>() { mmuPath }, new List <string>() { "C#", "C++CLR" }), new CSharpMMUInstantiator())) { //Start the adapter controller adapterController.Start(); Console.ReadLine(); } }
/// <summary> /// Basic awake method /// </summary> private void Awake() { //Determine if server build isServerBuild = IsHeadlessMode(); //Set the logger to a unity specific one (using debug log) MMICSharp.Adapter.Logger.Instance = new UnityLogger(isServerBuild) { //Log everything Level = Log_level.L_DEBUG }; //Assign the instance Instance = this; //Only visualizes the text if server build if (isServerBuild) { Console.WriteLine(@" __ __ _ __ ___ __ __ "); Console.WriteLine(@" / / / /___ (_) /___ __ / | ____/ /___ _____ / /____ _____"); Console.WriteLine(@" / / / / __ \/ / __ / / / / / /| |/ __ / __ `/ __ \/ __ / _ \/ ___ / "); Console.WriteLine(@"/ /_/ / / / / / /_/ /_/ / / ___ / /_/ / /_/ / /_/ / /_/ __/ / "); Console.WriteLine(@"\____/_/ /_/_/\__/\__, / /_/ |_\__,_/\__,_/ .___/\__/\___/_/ "); Console.WriteLine(@" /____/ /_/ "); Console.WriteLine(@"_________________________________________________________________"); } //Only use this if self_hosted and within edit mode -> Otherwise the launcher which starts the service assigns the address and port #if UNITY_EDITOR this.address.Address = "127.0.0.1"; this.address.Port = 8950; this.registerAddress.Port = 9009; this.registerAddress.Address = "127.0.0.1"; #else //Parse the command line arguments if (!this.ParseCommandLineArguments(System.Environment.GetCommandLineArgs())) { MMICSharp.Adapter.Logger.Log(Log_level.L_ERROR, "Cannot parse the command line arguments. The adapter is meant to be started with specified arguments only."); return; } #endif //Create a new session data this.sessionData = new SessionData(); //Create a session cleaner for the utilized session data this.sessionCleaner = new SessionCleaner(sessionData) { //Session shoould be cleaned after 60 minutes Timeout = TimeSpan.FromMinutes(60), //The session cleaner should check every minute UpdateTime = TimeSpan.FromMinutes(1) }; //Set the quality properties Application.targetFrameRate = 30; QualitySettings.SetQualityLevel(0, true); //Create an adapter description -> to do in future load properties such as the ID from file MAdapterDescription adapterDescription = new MAdapterDescription() { ID = "14456546241413414", Addresses = new List <MIPAddress>() { this.address }, Name = "UnityAdapter", Language = "UnityC#", Parameters = new List <MParameter>(), Properties = new Dictionary <string, string>() }; //Create a new adapter controller which listens on the file system and scans for MMUs this.adapterController = new AdapterController(this.sessionData, adapterDescription, mmiRegisterAddress, new FileBasedMMUProvider(sessionData, mmuPath, "UnityC#", "Unity"), new UnityMMUInstantiator()); //Log the startup info text MMICSharp.Adapter.Logger.Log(Log_level.L_INFO, $"Hosting thrift server at {this.address.Address} {this.address.Port}: "); }