コード例 #1
0
        private static void Main(string[] args)
        {
            // You can only create raw sockets with elevated privileges
            if (!UserInformation.IsAdmin())
            {
                var message = SystemInformation.IsWindows
                    ? "Please run with elevated prilileges"
                    : "Please run using sudo";

                Console.WriteLine(message);
                Environment.Exit(1);
            }

            var appOptions = ParseCommandLine(args);

            if (appOptions.ShowHelp)
            {
                ShowHelp(appOptions);
                Environment.Exit(0);
            }

            var nics = NetworkInterfaceInfo.GetInterfaces();

            if (!appOptions.InterfaceId.HasValue ||
                appOptions.InterfaceId > nics.Count - 1 ||
                appOptions.InterfaceId < 0)
            {
                Console.WriteLine("Invalid interface ID");
                ShowHelp(appOptions);
                Environment.Exit(3);
            }

            var filters = appOptions.BuildFilters();
            var nic     = nics[appOptions.InterfaceId !.Value];
コード例 #2
0
        private async static Task <JavaMapletGaussOutput> MatrixTutorResult(MapleLinearAlgebra engine, MapleMatrix matrix, string methodName)
        {
            await semaphore.WaitAsync();//Since same protocol is used for every Tutor we have to wait for other tutor's to be closed before we can recall.

            try
            {
                var engineType = typeof(MapleLinearAlgebra);
                var method     = engineType.GetMethod(methodName);                                     //reflection used since each Tutor uses same protocol, for linearalgebra, (but different call methods to maple)

                IWindow window = await(Task <IWindow>) method.Invoke(engine, new object[] { matrix }); // await engine.GaussJordanEliminationTutor(matrix);

                if (window is MSWindow)                                                                // Microsoft Windows
                {
                    // Find Loopback Pseudo interface for sniffing.
                    var nic = NetworkInterfaceInfo
                              .GetInterfaces()
                              .FirstOrDefault(c => c.Name.Contains("Loopback Pseudo"));

                    // Ensure loopback pseudo interface is found before we start trying to sniff.
                    if (nic != default(NetworkInterfaceInfo))
                    {
                        PcapNgFileOutput output;
                        SocketSniffer    sniffer;

                        StartSniffing(nic, out output, out sniffer);
                        await InteractWithDefaultTutor((MSWindow)window, sniffer);

                        StopSniffing(output, sniffer);
                        return(InterpretMatrixSniffedData());
                    }
                }
            } finally
            {
                semaphore.Release();
            }

            return(null);
        }
コード例 #3
0
        private async static Task <JavaMapletGaussOutput> TutorResult(MapleLinearAlgebra engine, MapleMatrix matrix, string methodName)
        {
            List <string> operations  = new List <string>();
            var           gaussOutput = new JavaMapletGaussOutput();

            await semaphoreSlim.WaitAsync();//Since same protocol is used for every Tutor we have to wait for other tutor's to be closed before we can recall.

            try
            {
                var engineType = typeof(MapleLinearAlgebra);
                var method     = engineType.GetMethod(methodName);                                     //reflection used since each Tutor uses same protocol, for linearalgebra, (but different call methods to maple)

                IWindow window = await(Task <IWindow>) method.Invoke(engine, new object[] { matrix }); // await engine.GaussJordanEliminationTutor(matrix);
                if (window is MSWindow)                                                                // Microsoft Windows
                {
                    // Find interfaces for sniffing.
                    var nics = NetworkInterfaceInfo.GetInterfaces();
                    var nic  = nics.FirstOrDefault(c => c.Name.Contains("Loopback Pseudo"));

                    // Ensure loopback pseudo interface is found...
                    if (nic != default(NetworkInterfaceInfo))
                    {
                        #region Start Sniffing
                        var appOptions = new AppOptions();
                        appOptions.Parse(new string[] { "" });
                        var filters = appOptions.BuildFilters();
                        var output  = new PcapNgFileOutput(nic, appOptions.Filename);
                        var sniffer = new SocketSniffer(nic, filters, output);
                        sniffer.Start();
                        #endregion

                        #region MSWIN
                        var mswin = (MSWindow)window;
                        mswin.WindowPos(0, 0, 400, 800);

                        for (int i = 0; i < 4; i++)
                        {
                            mswin.SendKeyStroke(System.Windows.Forms.Keys.Tab);
                            await Task.Delay(60);
                        }

                        mswin.SendKeyStroke(System.Windows.Forms.Keys.Enter);
                        mswin.Hide();
                        long LastPackageCount = 0;
                        int  WaitTries        = 0;
                        while (true) // wait for program to stop sending packages to intercept.
                        {
                            await Task.Delay(400);

                            LastPackageCount = sniffer.PacketsCaptured;
                            if (LastPackageCount > 0 && LastPackageCount == sniffer.PacketsCaptured)
                            {
                                WaitTries++;
                            }
                            if (WaitTries > 4)
                            {
                                break;
                            }
                        }
                        mswin.Close();
                        #endregion

                        #region Interpret Sniffed Data
                        sniffer.Stop();
                        output.Dispose();

                        using (var reader = new StreamReader("snifter.pcapng"))
                        {
                            var content = reader.ReadToEnd();
                            var regex   = new Regex(@"\<application_communications.*?\<content\>Applied operation\:\ (.*?)\<\/content\>", RegexOptions.Singleline);
                            var match   = regex.Match(content);

                            while (match.Success)
                            {
                                var operation = match.Groups[1].Value.Trim();//initial space
                                operations.Add(operation);
                                match = match.NextMatch();
                            }

                            var mapleMatrixRegex = new Regex(@"\<content\>(\&lt\;.*?)\<", RegexOptions.Singleline);
                            var mapleMatrixMatch = mapleMatrixRegex.Match(content);

                            var lastMatchStr = "";
                            while (mapleMatrixMatch.Success)
                            {
                                lastMatchStr     = mapleMatrixMatch.Groups[1].Value;
                                mapleMatrixMatch = mapleMatrixMatch.NextMatch();
                            }

                            StringBuilder builder = new StringBuilder(lastMatchStr);
                            gaussOutput.Operations = operations.ToArray();

                            int ra_index = 0;
                            int index    = 0;
                            var search   = "mtext&gt;&amp;NewLine;";
                            while ((ra_index = builder.ToString().IndexOf(search, ra_index)) != -1)
                            {
                                ra_index += search.Length;
                                if (index >= operations.Count)
                                {
                                    break;
                                }
                                builder.Insert(ra_index, $" {gaussOutput.OperationsDa[index++]} &amp;NewLine;&amp;NewLine;&amp;NewLine;");
                            }


                            gaussOutput.MathML = HttpUtility.HtmlDecode(builder.ToString());
                        }
                        #endregion
                    }
                }
            } finally
            {
                semaphoreSlim.Release();
            }

            return(gaussOutput);
        }