Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Reflection;
- // This sample is intended only for simple diagnostic purposes.
- // To use this program:
- // 1. Create a new "Visual C# -> Console Application".
- // 2. Replace the contents of `Program.cs` with this file.
- // 3. Add the "SSH.NET" NuGet package to the project.
- // 4. Replace all of the "REPLACE_WITH" strings with your info.
- // 5. Start debugging the program in Visual Studio.
- // If you receive the "Connected successfully." message you can enter a simple
- // command like "ls" and type return. That will hopefully list the contents of
- // the user directory on the Mac build host.
- using Renci.SshNet;
- using Renci.SshNet.Common;
- using System.Text;
- namespace SSHConsole
- {
- class Program
- {
- static string host = "replace with IP address of Mac";
- static string username = "replace with Mac user name";
- static string password = "Replace with Mac password";
- static void Main(string[] args)
- {
- var keyboardAuth = new KeyboardInteractiveAuthenticationMethod(username);
- var connectionInfo = new ConnectionInfo(host, username, keyboardAuth);
- // Allow 60 seconds for the connection to succeed
- connectionInfo.Timeout = new TimeSpan(0, 0, 60);
- keyboardAuth.AuthenticationPrompt += keyboardAuth_AuthenticationPrompt;
- using (var client = new SshClient(connectionInfo))
- {
- client.Connect();
- Console.WriteLine("Connected successfully.");
- var command = Console.ReadLine();
- while (command != "")
- {
- var runCommand = client.RunCommand(command);
- Console.WriteLine(runCommand.Result);
- command = Console.ReadLine();
- }
- client.Disconnect();
- }
- AppDomain currentDomain = AppDomain.CurrentDomain;
- currentDomain.AssemblyLoad += new AssemblyLoadEventHandler(MyAssemblyLoadEventHandler);
- PrintLoadedAssemblies(currentDomain);
- }
- // Code to determine where assemblies are being loaded from. Trying to establish whether
- static void keyboardAuth_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
- {
- foreach (var prompt in e.Prompts)
- {
- if (prompt.Request.StartsWith("Password:"))
- {
- prompt.Response = password;
- }
- }
- }
- static void PrintLoadedAssemblies(AppDomain domain)
- {
- Console.WriteLine("LOADED ASSEMBLIES: {0}", domain.GetAssemblies().Length);
- int count = 0;
- foreach (Assembly a in domain.GetAssemblies())
- {
- count++;
- Console.Write(count + ": ");
- try
- {
- // The last assembly in the array is a "Anonymously Hosted DynamicMethods Assembly"
- // so you can't get a location for it, throws NotSupportedException
- Console.WriteLine(a.Location + a.FullName);
- }
- catch (NotSupportedException ex)
- {
- Console.WriteLine(a.FullName);
- }
- }
- Console.WriteLine();
- Console.ReadLine();
- }
- static void MyAssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args)
- {
- Console.WriteLine("ASSEMBLY LOADED: " + args.LoadedAssembly.Location);
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement