ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
Revision: 88
Committed: 2004-03-01T19:03:40-08:00 (21 years, 3 months ago) by Douglas Thrift
File size: 2288 byte(s)
Log Message:
It seems to work, now we just need to get Host Update to work.

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

Properties

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