locked
c# windows web server ssh to clients RRS feed

  • Question

  • User1448655074 posted

    I have around 100 linux clients going up to perhaps 300-400 connected via vpn to a windows 2012 c# web server

    My project involves simultaneously launching ssh connections to the clients to either run or stop certain local applications.

    The connections will be made when the client boots up and a few times a days with ajax.

    the clients are displaying a kiosk style window via browser

    Questions:

    1.  Anyone done anything like this before and know how this could behave?

    2.  Any better suggestions/idea welcome?

    thanks

     

    Friday, September 21, 2018 11:25 PM

All replies

  • User475983607 posted

    By definition, web server do not connect to clients.  Clients connect to web servers.

    You have a bunch of web servers and no clients.  The main problem you're facing is the kiosks must have a TCP/UDP listener and the "Main Web Server" must know the IP and Port of all the kiosk listeners.  When the kiosks start they register themselves with the "Main Server" by passing their IP and PORT.  The next issue is making sure the "Main Server" can reach the kiosks.   Generally this involves firewalls and opening ports.

    Really, this is not an ASP.NET question at all.  This is a networking and socket programming question.  

    However, ASP.NET has a feature called SignalR which uses web sockets.  The client can open a connection to a web server and the client and the server can exchange messages through the connection.  Maybe take a look at SignalR and see if it solves the problem.

    https://docs.microsoft.com/en-us/aspnet/core/signalr/?view=aspnetcore-2.1

    Saturday, September 22, 2018 1:13 PM
  • User283571144 posted

    Hi Poly,

    My project involves simultaneously launching ssh connections to the clients to either run or stop certain local applications

    According to your description, I couldn't understand your requirement clearly.

    Could you please tell me whhcih the ocal applications  you want to stop? Client-side or server-side?

    If you want to stop client-side application, this is not security.

    Normally we don't have the permission to manage client-side app in the browser.

    If you still want to manage the client linux, you should know the account and password, then using ssh to connect to the linux and run command to stop it.

    About how to run ssh in asp.net, you could refer to below codes:

    Install this package:

    https://www.nuget.org/packages/SSH.NET/

    using Renci.SshNet;
    using System;
     
    namespace ConsoleApp
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    using (var client = new SshClient("server ip address", "your user name", "your password"))
                    {
                        client.Connect();
                        Console.WriteLine("Connected");
     
                        string result = client.RunCommand("ifconfig -a").Execute();
                        Console.WriteLine(result);
     
                        client.Disconnect();
                        Console.WriteLine("Disconnected");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
     
                Console.ReadLine();
            }
        }
    }
     
    

    Result:

    Best Regards,

    Brando

    Monday, September 24, 2018 6:17 AM