public VaddioControlTelnet(ILogger <VaddioControlTelnet> logger)
 {
     _logger = logger;
     // _telnet = new PrimS.Telnet.Client("10.0.0.5", 23, default);
     _telnet = new PrimS.Telnet.Client("localhost", 2701, default);
     _logger.LogInformation("Logging in");
     var result = _telnet.TryLoginAsync("admin", "password", 1000).Result;
 }
        public static bool IsLocalSftpServerRunning()
        {
            string sftpServerHostAddress = ConfigurationManager.AppSettings["sftpServerHostAddress"];
            int    sftpServerPortNo      = Convert.ToInt32(ConfigurationManager.AppSettings["sftpServerPortNo"]);

            using (PrimS.Telnet.Client telnetClient = new PrimS.Telnet.Client(sftpServerHostAddress, sftpServerPortNo, new System.Threading.CancellationToken()))
            {
                return(telnetClient.IsConnected);
            }
        }
Esempio n. 3
0
        private static async Task SendCommand(PrimS.Telnet.Client client, string command, params object[] args)
        {
            var formatted = string.Format(command, args);

            Console.WriteLine(formatted);
            await client.WriteLine(formatted + "\n");

            var result = await client.ReadAsync();

            Console.Write(result);
        }
Esempio n. 4
0
 public static bool IsConnect(string address, int port)
 {
     try
     {
         using (var client = new PrimS.Telnet.Client("127.0.0.1", 9201, new System.Threading.CancellationToken()))
         {
             return(client.IsConnected);
         }
     }
     catch
     {
         return(false);
     }
 }
Esempio n. 5
0
        static void Main(string[] args)
        {
            System.Threading.CancellationToken token = new System.Threading.CancellationToken();
            PrimS.Telnet.Client tc = new PrimS.Telnet.Client(args[0], Convert.ToInt32(args[1]), token);
            string cmd             = string.Empty;

            do
            {
                //string result = await tc.ReadAsync();
                Task <string> task = tc.ReadAsync();
                Console.WriteLine(task.Result);

                if (cmd.Equals("quit", StringComparison.CurrentCultureIgnoreCase))
                {
                    break;
                }

                //Console.WriteLine(result);

                cmd = Console.ReadLine();
                tc.WriteLine(cmd);
            }while (true);
        }
Esempio n. 6
0
        private static async Task RunTelnetSession()
        {
            string lastPart;

            using (var client = new PrimS.Telnet.Client("skillz.baectf.com", 443, new System.Threading.CancellationToken()))
            {
                var challenge = await client.ReadAsync();

                Console.WriteLine(challenge);
                await client.WriteLine(password + "\n");

                while (true)
                {
                    string line = await client.ReadAsync();

                    lastPart = line;
                    if (!string.IsNullOrEmpty(line))
                    {
                        Console.WriteLine(line);
                    }
                    if (line.Contains("Enter command:"))
                    {
                        break;
                    }
                }

                await KillZombies(client);

                // level 2
                await KillZombies(client);

                // level 3
                //await KillZombies(client);
                //var r = await client.ReadAsync();
                //Console.WriteLine(r);
            }
        }
Esempio n. 7
0
        private static async Task KillZombies(PrimS.Telnet.Client client)
        {
            await client.WriteLine("LOOK\n");

            var lookResult = await client.ReadAsync();

            Console.Write(lookResult);
            var playerPositionLine = playerPositionRegex.Match(lookResult).Value;
            var rotationLine       = playerRotationRegex.Match(lookResult).Value;
            var rotationStr        = new Regex(@"[\d\.]+").Match(rotationLine).Value;
            var rotation           = double.Parse(rotationStr);
            var player             = new Player()
            {
                Position = new Position(playerPositionLine),
                Angle    = rotation
            };

            Console.WriteLine(player);

            var zombieMatches   = zombiePositionRegex.Matches(lookResult);
            var zombiePositions = new List <Position>();

            foreach (Match zm in zombieMatches)
            {
                var pos = new Position(zm.Value);
                zombiePositions.Add(pos);
            }

            foreach (var zp in zombiePositions)
            {
                var angle = player.FacePosition(zp);
                await SendCommand(client, "ROTATE {0}", angle);
                await SendCommand(client, "FIRE");
            }
            //await SendCommand(client, "LOOK");
        }