I am writing a c# SSH tunneling program to consolidate dynamic tunneling into a single program, instead of using putty+firefox socks4/chrome socks4 plugin, typing in the same user/pass..ect. It is using the Renci.SSHNet library.
My question is this: When I create a new SshClient object, I want to be able to kill that connection later from a kill connection button, and also be able to run a separate thread that says while(isConnected) if (!addedToList) addtolist..The issue is that I am unsure of how to access different simultaneous running sshClient objects. Say I have 3 open connections to different hosts. If I select the host ip from current connections, I need a way to connect that ip address with the SshCLient connections and then run sshClient.Disconnect(). I realize that you can use sshClient.ConnectionInfo.Host.ToString() and match a string to that, but again if I am in a different method (kill connection button clicked) I don't know how to match host ip of 192.168.1.1 to an sshClient that is connected to that host.
I looked into weak references, but that seems to only work if I had only one sshClient. If there was a way to access currently created SshClient objects, then match it to the Host ip property, it would work. I can't find this in the Google.
I thought about scheming some elaborate way to create private object variable SshClients that are named after deviceIpString, but was unsure of how to create a variable that is named after another variable's contents (String). such as:
deviceIpString = 192.168.1.1;
(i am pretending that backticks access the variable's data, since I dont know how to do it)
private SshClient 'deviceIpString' = new (SshClient(arguments));