Last active
November 14, 2016 21:12
-
-
Save jgold6/c9be43ebed906268124a868f68566503 to your computer and use it in GitHub Desktop.
List loaded assemblies when connecting to the mac fmor vs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment