Exemplo n.º 1
0
        private static void ListAdapterNames(LocalNetworkNode node)
        {
            NetworkAdapter[] entries = node.GetAllAdapters();
            Console.WriteLine("Adapters: ");

            for (int i = 0; i < entries.Length; i++)
            {
                NetworkAdapter entry = entries[i];

                Console.WriteLine(
                    "{0}:\n\tEntry Address: {1}\n\tEntry GUID: {2}\n\tEntry Connected: {3}",
                    i,
                    entry.NetworkAddress,
                    entry.GUID,
                    entry.IsConnected
                    );
            }
        }
Exemplo n.º 2
0
        private static void ListAdapterPorts(LocalNetworkNode node, string guid)
        {
            NetworkAdapter adapter = Find(node, guid);

            NetworkPortListener[] entries = adapter.GetAllPortListeners();
            Console.WriteLine("Ports for Adapter: {0}", guid);

            for (int i = 0; i < entries.Length; i++)
            {
                NetworkPortListener entry = entries[i];

                Console.WriteLine(
                    "{0}\n\tIs Open: {1}\n\tPacket Count: {2}",
                    entry.GetIdentity(),
                    entry.IsOpen,
                    entry.PacketCount
                    );
            }
        }
Exemplo n.º 3
0
 private static NetworkAdapter Find(LocalNetworkNode node, string guid)
 {
     return(node.GetAllAdapters().FirstOrDefault(x => x.GUID.StartsWith(guid)));
 }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            Dictionary <string, Command> cmds = new Dictionary <string, Command>();

            AppRootHelper.SetAppDomainBase();
            Logger.OnLogReceive += (x, y) => Console.WriteLine($"[{x}] {y}");
            int port = args.Length > 0 ? int.Parse(args[0]) : 42069;
            LocalNetworkNode     node     = new LocalNetworkNode();
            NetworkTunnelService tService = new NetworkTunnelService(node, port);

            cmds.Add(
                "dns-names",
                new Command(
                    "dns-names",
                    (s) => ListDnsNames(node.DNSAdapter),
                    "Lists all known hostnames",
                    0
                    )
                );

            cmds.Add(
                "adapters",
                new Command("adapters", (s) => ListAdapterNames(node), "Lists all known adatpers", 0)
                );

            cmds.Add(
                "ports",
                new Command(
                    "ports",
                    (s) => ListAdapterPorts(node, s[0]),
                    "Lists all Ports of the Adapter specified by partical or complete GUID",
                    1
                    )
                );

            cmds.Add("clear", new Command("clear", (s) => Console.Clear(), "Clears the Console", 0));

            cmds.Add(
                "tunnels",
                new Command(
                    "tunnels",
                    (s) => ListActiveTunnels(tService),
                    "Lists all Active Tunnel Connections",
                    0
                    )
                );

            cmds.Add(
                "dns-rem",
                new Command(
                    "dns-rem",
                    (s) => ClearDNSName(node.DNSAdapter, s),
                    "Removes all specified DNS Names",
                    0
                    )
                );

            tService.Start();
            Thread.Sleep(1000);
            string cmd = null;

            Console.WriteLine("Type 'help' to display a list of commands.");

            while (true)
            {
                Console.Write("visnet> ");
                cmd = Console.ReadLine();

                if (cmd.ToLower() == "help")
                {
                    Console.WriteLine("Commands: ");
                    Console.WriteLine("\texit => Exits visnet");
                    Console.WriteLine("\thelp => Displays this Help Text");

                    foreach (KeyValuePair <string, Command> kvp in cmds)
                    {
                        Console.WriteLine("\t{0} => {1}", kvp.Key, kvp.Value.HelpText);
                    }
                }
                else if (cmd.ToLower() == "exit")
                {
                    break;
                }

                string[] ar = cmd.Split(' ', StringSplitOptions.RemoveEmptyEntries);

                if (ar.Length == 0 || !cmds.ContainsKey(ar[0]))
                {
                    Console.WriteLine("Invalid Command: " + cmd);
                }
                else
                {
                    Command command = cmds[ar[0]];

                    if (!command.TryExecute(ar.Skip(1).ToArray()))
                    {
                        Console.WriteLine("Command Failed.");
                    }
                }
            }

            node.UnloadNode();
            tService.Stop();
        }