ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
Revision: 98
Committed: 2004-03-02T01:17:58-08:00 (21 years, 3 months ago) by Douglas Thrift
File size: 2852 byte(s)
Log Message:
Hello nurse!

File Contents

# User Rev Content
1 Douglas Thrift 77 // Host Update Sharp
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     using System;
8     using System.IO;
9     using System.Net;
10 Douglas Thrift 82 using System.Text;
11 Douglas Thrift 98 #if !_FreeBSD_
12     using System.Windows.Forms;
13     #endif
14 Douglas Thrift 77
15 Douglas Thrift 78 public class HostUpdateSharp
16 Douglas Thrift 77 {
17 Douglas Thrift 78 public static void Main(string[] args)
18 Douglas Thrift 77 {
19 Douglas Thrift 98 foreach (string arg in args)
20     {
21     switch (arg)
22     {
23     case "-D":
24     debug = true;
25     break;
26     }
27     }
28    
29 Douglas Thrift 90 try
30     {
31     new HostUpdateSharp();
32     }
33     catch (Exception exception) { Console.Error.WriteLine(exception); }
34     }
35     public HostUpdateSharp()
36     {
37 Douglas Thrift 83 StringBuilder host = new StringBuilder("host=" + Dns.GetHostName());
38 Douglas Thrift 78 string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi";
39    
40 Douglas Thrift 88 if ((host + "").IndexOf('.') < 0)
41 Douglas Thrift 82 {
42     host.Append(".local.douglasthrift.net");
43     }
44    
45 Douglas Thrift 96 WebHeaderCollection headers = new WebHeaderCollection();
46 Douglas Thrift 93
47 Douglas Thrift 96 headers.Add("Authorization", "Basic " + Convert.ToBase64String((new
48     ASCIIEncoding()).GetBytes("HostUpdate:frell2003")));
49 Douglas Thrift 93
50 Douglas Thrift 82 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
51    
52     request.Accept = "text/plain";
53 Douglas Thrift 83 request.ContentLength = host.Length;
54 Douglas Thrift 82 request.ContentType = "application/x-www-form-urlencoded";
55 Douglas Thrift 96 request.Headers = headers;
56 Douglas Thrift 83 request.KeepAlive = false;
57 Douglas Thrift 82 request.Method = "POST";
58 Douglas Thrift 88 request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')';
59    
60     StreamWriter post = new StreamWriter(request.GetRequestStream(),
61     Encoding.ASCII);
62    
63     post.Write(host);
64     post.Close();
65    
66     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
67    
68     StreamReader content = new StreamReader(response.GetResponseStream(),
69     Encoding.ASCII);
70    
71 Douglas Thrift 98 #if _FreeBSD_
72     if (debug) Console.Write(content.ReadToEnd());
73     #else
74     if (debug) MessageBox.Show(content.ReadToEnd(), "Host Update Sharp",
75     MessageBoxButtons.OK, MessageBoxIcon.Information);
76     #endif
77    
78 Douglas Thrift 90 content.Close();
79 Douglas Thrift 77 }
80 Douglas Thrift 98 private static bool debug = false;
81 Douglas Thrift 88 #if _FreeBSD_
82 Douglas Thrift 90 private string platform() { return "FreeBSD 4.9-STABLE i386"; }
83 Douglas Thrift 88 #else
84 Douglas Thrift 90 private string platform()
85 Douglas Thrift 88 {
86     OperatingSystem os = Environment.OSVersion;
87     string system = "Unknown";
88    
89     switch (os.Platform)
90     {
91     case PlatformID.Win32NT:
92     system = "Windows NT";
93     break;
94     case PlatformID.Win32Windows:
95     system = "Windows";
96     break;
97     }
98    
99     int major = os.Version.Major, minor = os.Version.Minor;
100     string version = os + "";
101    
102     switch (system)
103     {
104     case "Windows NT":
105     switch (major)
106     {
107     case 5:
108     switch (minor)
109     {
110     case 0:
111     version = "Windows 2000";
112     break;
113     case 1:
114     version = "Windows XP";
115     break;
116     case 2:
117     version = "Windows .NET Server";
118     break;
119     }
120     break;
121     }
122     break;
123     case "Windows":
124     if (major == 4)
125     {
126     switch (minor)
127     {
128     case 10:
129     version = " Windows 98";
130     break;
131     case 90:
132     version = " Windows ME";
133     break;
134     }
135     }
136     break;
137     }
138    
139     return system + ' ' + major + '.' + minor + " [" + version + "] ix86";
140     }
141     #endif
142 Douglas Thrift 77 }

Properties

Name Value
svn:eol-style native
svn:keywords Id