ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
Revision: 96
Committed: 2004-03-02T00:26:19-08:00 (21 years, 3 months ago) by Douglas Thrift
File size: 2493 byte(s)
Log Message:
Maybe, just maybe!

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

Properties

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