blob: 003a3a66e13b76b1e89e75f0c7c425022cdf9242 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 | using System;
using System.Diagnostics;
using Gtk;
using Avahi.UI;
public class EntryPoint {
    public static void Main () {
        Application.Init (); 
		
        ServiceDialog dialog = new ServiceDialog ("Choose SSH Server", null,
                                                  Stock.Cancel, ResponseType.Cancel,
                                                  Stock.Connect, ResponseType.Accept);
	dialog.BrowseServiceTypes = new string[] { "_ssh._tcp" };
        dialog.ResolveServiceEnabled = true;
        if (dialog.Run () == (int) ResponseType.Accept) {
            Console.WriteLine ("Connecting to {0}:{1}", dialog.Address, dialog.Port);
            string user = Environment.UserName;
            
            foreach (byte[] txtBytes in dialog.TxtData) {
                string txt = System.Text.Encoding.UTF8.GetString (txtBytes);
                string[] splitTxt = txt.Split(new char[] { '=' }, 2);
                
                if (splitTxt.Length != 2)
                    continue;
                if (splitTxt[0] == "u") {
                    user = splitTxt[1];
                }
                string args = String.Format ("gnome-terminal -t {0} -x ssh -p {1} -l {2} {3}",
                                             dialog.HostName, dialog.Port, user, dialog.Address.ToString ());
                Console.WriteLine ("Launching: " + args);
                Process.Start (args);
            }
        }
    }
}
 |