Advertisement
Guest User

Untitled

a guest
Nov 14th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. using System;
  2. using System.Reflection;
  3.  
  4.  
  5. // This sample is intended only for simple diagnostic purposes.
  6.  
  7. // To use this program:
  8. // 1. Create a new "Visual C# -> Console Application".
  9. // 2. Replace the contents of `Program.cs` with this file.
  10. // 3. Add the "SSH.NET" NuGet package to the project.
  11. // 4. Replace all of the "REPLACE_WITH" strings with your info.
  12. // 5. Start debugging the program in Visual Studio.
  13.  
  14. // If you receive the "Connected successfully." message you can enter a simple
  15. // command like "ls" and type return. That will hopefully list the contents of
  16. // the user directory on the Mac build host.
  17.  
  18. using Renci.SshNet;
  19. using Renci.SshNet.Common;
  20. using System.Text;
  21.  
  22. namespace SSHConsole
  23. {
  24. class Program
  25. {
  26. static string host = "replace with IP address of Mac";
  27. static string username = "replace with Mac user name";
  28. static string password = "Replace with Mac password";
  29.  
  30. static void Main(string[] args)
  31. {
  32. var keyboardAuth = new KeyboardInteractiveAuthenticationMethod(username);
  33. var connectionInfo = new ConnectionInfo(host, username, keyboardAuth);
  34.  
  35. // Allow 60 seconds for the connection to succeed
  36. connectionInfo.Timeout = new TimeSpan(0, 0, 60);
  37.  
  38. keyboardAuth.AuthenticationPrompt += keyboardAuth_AuthenticationPrompt;
  39.  
  40. using (var client = new SshClient(connectionInfo))
  41. {
  42. client.Connect();
  43. Console.WriteLine("Connected successfully.");
  44. var command = Console.ReadLine();
  45. while (command != "")
  46. {
  47. var runCommand = client.RunCommand(command);
  48. Console.WriteLine(runCommand.Result);
  49. command = Console.ReadLine();
  50. }
  51. client.Disconnect();
  52. }
  53.  
  54. AppDomain currentDomain = AppDomain.CurrentDomain;
  55. currentDomain.AssemblyLoad += new AssemblyLoadEventHandler(MyAssemblyLoadEventHandler);
  56.  
  57. PrintLoadedAssemblies(currentDomain);
  58.  
  59. }
  60.  
  61. // Code to determine where assemblies are being loaded from. Trying to establish whether
  62. static void keyboardAuth_AuthenticationPrompt(object sender, AuthenticationPromptEventArgs e)
  63. {
  64. foreach (var prompt in e.Prompts)
  65. {
  66. if (prompt.Request.StartsWith("Password:"))
  67. {
  68. prompt.Response = password;
  69. }
  70. }
  71. }
  72.  
  73. static void PrintLoadedAssemblies(AppDomain domain)
  74. {
  75. Console.WriteLine("LOADED ASSEMBLIES: {0}", domain.GetAssemblies().Length);
  76. int count = 0;
  77. foreach (Assembly a in domain.GetAssemblies())
  78. {
  79. count++;
  80. Console.Write(count + ": ");
  81. try
  82. {
  83. // The last assembly in the array is a "Anonymously Hosted DynamicMethods Assembly"
  84. // so you can't get a location for it, throws NotSupportedException
  85. Console.WriteLine(a.Location + a.FullName);
  86. }
  87. catch (NotSupportedException ex)
  88. {
  89. Console.WriteLine(a.FullName);
  90. }
  91. }
  92. Console.WriteLine();
  93. Console.ReadLine();
  94. }
  95.  
  96. static void MyAssemblyLoadEventHandler(object sender, AssemblyLoadEventArgs args)
  97. {
  98. Console.WriteLine("ASSEMBLY LOADED: " + args.LoadedAssembly.Location);
  99. Console.WriteLine();
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement