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