ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
Revision: 92
Committed: 2004-03-01T23:23:39-08:00 (21 years, 3 months ago) by Douglas Thrift
File size: 2385 byte(s)
Log Message:
Don't need that!

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     HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
33    
34     request.Accept = "text/plain";
35 Douglas Thrift 83 request.ContentLength = host.Length;
36 Douglas Thrift 82 request.ContentType = "application/x-www-form-urlencoded";
37     request.Credentials = new NetworkCredential("HostUpdate", "frell2003");
38 Douglas Thrift 83 request.KeepAlive = false;
39 Douglas Thrift 82 request.Method = "POST";
40 Douglas Thrift 83 request.PreAuthenticate = true;
41 Douglas Thrift 88 request.UserAgent = "Host Update Sharp/1.0 (" + platform() + ')';
42    
43     StreamWriter post = new StreamWriter(request.GetRequestStream(),
44     Encoding.ASCII);
45    
46     post.Write(host);
47     post.Close();
48    
49     HttpWebResponse response = (HttpWebResponse)request.GetResponse();
50    
51     StreamReader content = new StreamReader(response.GetResponseStream(),
52     Encoding.ASCII);
53    
54     Console.Write(content.ReadToEnd());
55 Douglas Thrift 90 content.Close();
56 Douglas Thrift 77 }
57 Douglas Thrift 88 #if _FreeBSD_
58 Douglas Thrift 90 private string platform() { return "FreeBSD 4.9-STABLE i386"; }
59 Douglas Thrift 88 #else
60 Douglas Thrift 90 private string platform()
61 Douglas Thrift 88 {
62     OperatingSystem os = Environment.OSVersion;
63     string system = "Unknown";
64    
65     switch (os.Platform)
66     {
67     case PlatformID.Win32NT:
68     system = "Windows NT";
69     break;
70     case PlatformID.Win32Windows:
71     system = "Windows";
72     break;
73     }
74    
75     int major = os.Version.Major, minor = os.Version.Minor;
76     string version = os + "";
77    
78     switch (system)
79     {
80     case "Windows NT":
81     switch (major)
82     {
83     case 5:
84     switch (minor)
85     {
86     case 0:
87     version = "Windows 2000";
88     break;
89     case 1:
90     version = "Windows XP";
91     break;
92     case 2:
93     version = "Windows .NET Server";
94     break;
95     }
96     break;
97     }
98     break;
99     case "Windows":
100     if (major == 4)
101     {
102     switch (minor)
103     {
104     case 10:
105     version = " Windows 98";
106     break;
107     case 90:
108     version = " Windows ME";
109     break;
110     }
111     }
112     break;
113     }
114    
115     return system + ' ' + major + '.' + minor + " [" + version + "] ix86";
116     }
117     #endif
118 Douglas Thrift 77 }

Properties

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