]> git.meshlink.io Git - catta/blob - avahi-ui-sharp/bssh.cs
fa3d4d480c5189ec67448229937feb4fca1dc9a2
[catta] / avahi-ui-sharp / bssh.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,
11                                                   Stock.Cancel, ResponseType.Cancel,
12                                                   Stock.Connect, ResponseType.Accept);
13         dialog.BrowseServiceTypes = new string[] { "_ssh._tcp" };
14         dialog.ResolveServiceEnabled = true;
15
16         if (dialog.Run () == (int) ResponseType.Accept) {
17             Console.WriteLine ("Connecting to {0}:{1}", dialog.Address, dialog.Port);
18
19             string user = Environment.UserName;
20
21             foreach (byte[] txtBytes in dialog.TxtData) {
22                 string txt = System.Text.Encoding.UTF8.GetString (txtBytes);
23                 string[] splitTxt = txt.Split(new char[] { '=' }, 2);
24
25                 if (splitTxt.Length != 2)
26                     continue;
27
28                 if (splitTxt[0] == "u") {
29                     user = splitTxt[1];
30                 }
31
32                 string args = String.Format ("gnome-terminal -t {0} -x ssh -p {1} -l {2} {3}",
33                                              dialog.HostName, dialog.Port, user, dialog.Address.ToString ());
34                 Console.WriteLine ("Launching: " + args);
35                 Process.Start (args);
36             }
37         }
38     }
39 }