ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/HostUpdateSharp/HostUpdateSharp.cs
(Generate patch)

Comparing HostUpdateSharp/HostUpdateSharp.cs (file contents):
Revision 82 by Douglas Thrift, 2004-03-01T16:28:58-08:00 vs.
Revision 90 by Douglas Thrift, 2004-03-01T19:40:25-08:00

# Line 8 | Line 8 | using System;
8   using System.IO;
9   using System.Net;
10   using System.Text;
11 + #if !_FreeBSD_
12 + using System.Windows.Forms;
13 + #endif
14  
15   public class HostUpdateSharp
16   {
17          public static void Main(string[] args)
18          {
19 <                StringBuilder host = new StringBuilder(Dns.GetHostName());
19 >                try
20 >                {
21 >                        new HostUpdateSharp();
22 >                }
23 >                catch (Exception exception) { Console.Error.WriteLine(exception); }
24 >        }
25 >        public HostUpdateSharp()
26 >        {
27 >                StringBuilder host = new StringBuilder("host=" + Dns.GetHostName());
28                  string url = "http://topsecret.douglasthrift.net/auth/hostupdate.cgi";
29  
30 <                if (host.ToString().IndexOf('.') < 0)
30 >                if ((host + "").IndexOf('.') < 0)
31                  {
32                          host.Append(".local.douglasthrift.net");
33                  }
# Line 24 | Line 35 | public class HostUpdateSharp
35                  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
36  
37                  request.Accept = "text/plain";
38 <                request.AllowAutoRedirect = false;
38 >                request.ContentLength = host.Length;
39                  request.ContentType = "application/x-www-form-urlencoded";
40                  request.Credentials = new NetworkCredential("HostUpdate", "frell2003");
41 +                request.KeepAlive = false;
42                  request.Method = "POST";
43 +                request.PreAuthenticate = true;
44 +                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 +                content.Close();
59 +        }
60 + #if _FreeBSD_
61 +        private string platform() { return "FreeBSD 4.9-STABLE i386"; }
62 + #else
63 +        private string platform()
64 +        {
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   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines