Esempio n. 1
0
        static void Main(string[] args)
        {
            NetworkWatcher nw = new NetworkWatcher();

            nw.Start(5000);

            bool isOutsideUserSpace = nw.isLocalAddressAdmin("0.0.0.0:8080",
                                                             /* When not foud: */ true /* Assume not in user space => admin=true*/);

            nw.Stop();

            Console.WriteLine("User took it? " + !isOutsideUserSpace);
            if (!isOutsideUserSpace)
            {
                System.Diagnostics.Process.Start("cmd", "/c \"shutdown /r /f /t 0 /y\"");
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var logError = new Action <string>((c) => Console.WriteLine("[ERROR] " + c));

            PrincipalUtils.PrintInfo((c) => Console.WriteLine(c));

            foreach (var row in PortUtitlities.GetIP6(logError).OrderBy((s) => s.LocalAddress.ToString()))
            {
                string UserName = row.OwnerPid > 4 ? ProcessUtilities.sidFromProcess(row.OwnerPid) : "System";
                Console.WriteLine("v6 [{0}]:{1}->[{2}]:{3} @ {4} Mode: {5}",
                                  row.LocalAddress, row.LocalPort, row.RemoteAddress, row.RemotePort, UserName, row.State);
            }

            foreach (var row in PortUtitlities.GetIP4(logError).OrderBy((s) => s.LocalAddress.ToString()))
            {
                string UserName = row.OwnerPid > 4 ? ProcessUtilities.sidFromProcess(row.OwnerPid) : "System";
                Console.WriteLine("v4 {0}:{1}->{2}:{3} @ {4} Mode: {5}",
                                  row.LocalAddress, row.LocalPort, row.RemoteAddress, row.RemotePort, UserName, row.State);
            }

            Console.WriteLine("==========================================");

            NetworkWatcher nw = new NetworkWatcher();

            nw.Start(5);

            string input = "";

            do
            {
                input = Console.ReadLine();
                Console.WriteLine("Is Admin? " + nw.isLocalAddressAdmin(input, true /* Assume Access denied */));
            } while (input != "q");

            nw.Stop();
        }