-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo-file-Program.cs
227 lines (202 loc) · 8.2 KB
/
demo-file-Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Server Status Checker
//
// Copyright © Hackafortani, 2013
// Developed by Ilyas Kolasinac Osmanogullari || http://www.ilyax.com
// http://www.hackafortanfoni.com || http://www.alafortanfoni.com
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using Microsoft.Win32;
namespace IISChecker
{
class Program
{
public static string server { get; set; }
public static string database { get; set; }
public static string username { get; set; }
public static string password { get; set; }
static ConsoleSpinner sp = new ConsoleSpinner();
static Thread th;
static void Main(string[] args)
{
try
{
Console.WriteLine("");
Console.WriteLine("--------------------- HackaFortanFoni Server Status Checker ----------------------");
Console.WriteLine("********* --- .NET Framework Version --- **************************************");
CheckFrameworkVersion();
Console.WriteLine("********* --- .NET Framework Version End /--- *********************************");
Console.WriteLine("");
Console.WriteLine("********* --- IIS Version --- **************************************");
Console.WriteLine(GetIISVersion());
Console.WriteLine("********* --- .IIS Version End /--- *********************************");
Console.WriteLine("");
Console.WriteLine("********* --- SQL Server --- **************************************");
Console.WriteLine("Do you want to check SQL SERVER Y/N");
string sqlCheck = Console.ReadLine().ToUpper();
if (sqlCheck == "Y")
{
Console.Write("Server = ");
server = Console.ReadLine();
Console.Write("Database = ");
database = Console.ReadLine();
Console.Write("UserName = ");
username = Console.ReadLine();
Console.Write("Password = ");
password = Console.ReadLine();
CheckSQLServer();
}
Console.WriteLine("********* --- SQL Server End /--- *********************************");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
Console.ReadLine();
}
/// <summary>
/// .NET Framework
/// </summary>
public static void CheckFrameworkVersion()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
if (versionKeyName.StartsWith("v"))
{
RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", "");
string sp = versionKey.GetValue("SP", "").ToString();
string install = versionKey.GetValue("Install", "").ToString();
if (install == "") //no install info, ust be later
Console.WriteLine(versionKeyName + " " + name);
else
{
if (sp != "" && install == "1")
{
Console.WriteLine(versionKeyName + " " + name + " SP" + sp);
}
}
if (name != "")
{
continue;
}
foreach (string subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", "");
if (name != "")
sp = subKey.GetValue("SP", "").ToString();
install = subKey.GetValue("Install", "").ToString();
if (install == "") //no install info, ust be later
Console.WriteLine(versionKeyName + " " + name);
else
{
if (sp != "" && install == "1")
{
Console.WriteLine(" " + subKeyName + " " + name + " SP" + sp);
}
else if (install == "1")
{
Console.WriteLine(" " + subKeyName + " " + name);
}
}
}
}
}
}
}
/// <summary>
/// IIS
/// </summary>
/// <returns></returns>
public static Version GetIISVersion()
{
using (RegistryKey componentsKey =
Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\InetStp", false))
{
if (componentsKey != null)
{
int majorVersion = (int)componentsKey.GetValue("MajorVersion", -1);
int minorVersion = (int)componentsKey.GetValue("MinorVersion", -1);
if (majorVersion != -1 && minorVersion != -1)
{
return new Version(majorVersion, minorVersion);
}
}
return new Version(0, 0);
}
}
/// <summary>
/// SQL Server
/// </summary>
public static void CheckSQLServer()
{
try
{
string connectionString = string.Format("Server={0};Database={1};User Id={2};Password={3};", server, database, username, password);
using (SqlConnection conn =
new SqlConnection(connectionString))
{
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM INFORMATION_SCHEMA.TABLES";
th = new Thread(new ThreadStart(loading));
th.Start();
conn.Open();
th.Abort();
Console.WriteLine("");
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr.GetString(2));
}
}
}
catch (Exception ex)
{
th.Abort();
Console.WriteLine(ex.ToString());
}
}
/// <summary>
/// Loading Animation
/// </summary>
private static void loading()
{
while (true)
{
sp.Turn();
}
}
}//class end
class ConsoleSpinner
{
int counter;
public void ConsoleSpiner()
{
counter = 0;
}
public void Turn()
{
counter++;
switch (counter % 4)
{
case 0: Console.Write("/"); break;
case 1: Console.Write("-"); break;
case 2: Console.Write("\\"); break;
case 3: Console.Write("|"); break;
}
Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
System.Threading.Thread.Sleep(100);
}
}
}