ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
Revision: 90
Committed: 2004-03-01T19:40:25-08:00 (21 years, 3 months ago) by Douglas Thrift
File size: 2435 byte(s)
Log Message:
What a world!

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

Properties

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