Disable reset admin password, added open selected computer cups

Signed-off-by: Lev Rusanov <30170278+JDM170@users.noreply.github.com>
This commit is contained in:
2024-10-23 22:27:18 +07:00
parent 663bbc92c8
commit 5580d2cb9c

View File

@@ -24,10 +24,16 @@ namespace domain_utility
{ "Членство в глобальных группах", @"([*].+)", "Член групп:\t" } { "Членство в глобальных группах", @"([*].+)", "Член групп:\t" }
}; };
static readonly string[,] computerNameRegex = new string[,] {
{ "^[a-zA-Z]+\\d+$", "R54-630300" }, // THE01
{ "^\\d+[a-zA-Z]+\\d+$", "R54-" }, // 630300THE01
{ "^[rR]\\d*[-]\\d+[a-zA-Z]+\\d+$", "-" } // R54-630300THE01
};
private static string PingHost(string host) private static string PingHost(string host)
{ {
string returnMessage = string.Empty; string returnMessage = string.Empty;
//PingOptions pingOptions = new PingOptions(128, true); //PingOptions pingOptions = new PingOptions(128, true); // TTL = 128
PingOptions pingOptions = new PingOptions() { DontFragment = true }; PingOptions pingOptions = new PingOptions() { DontFragment = true };
using (Ping ping = new Ping()) using (Ping ping = new Ping())
{ {
@@ -45,7 +51,10 @@ namespace domain_utility
{ {
case IPStatus.Success: case IPStatus.Success:
{ {
returnMessage = string.Format("Ответ от {0}: число байт={1} время={2}ms TTL={3}", pingReply.Address, pingReply.Buffer.Length, pingReply.RoundtripTime, pingReply.Options.Ttl); if (pingReply.RoundtripTime < 1)
returnMessage = string.Format("Ответ от {0}: число байт={1} время<1ms TTL={2}", pingReply.Address, pingReply.Buffer.Length, pingReply.Options.Ttl);
else
returnMessage = string.Format("Ответ от {0}: число байт={1} время={2}ms TTL={3}", pingReply.Address, pingReply.Buffer.Length, pingReply.RoundtripTime, pingReply.Options.Ttl);
//averageTime += pingReply.RoundtripTime; //averageTime += pingReply.RoundtripTime;
break; break;
} }
@@ -98,13 +107,12 @@ namespace domain_utility
//Console.WriteLine("MinPasswordAge: " + directoryEntry.Properties["MinPasswordAge"].Value); //Console.WriteLine("MinPasswordAge: " + directoryEntry.Properties["MinPasswordAge"].Value);
//Console.WriteLine(TimeSpan.FromSeconds((int)directoryEntry.Properties["MinPasswordAge"].Value) - TimeSpan.FromSeconds((int)directoryEntry.Properties["PasswordAge"].Value)); //Console.WriteLine(TimeSpan.FromSeconds((int)directoryEntry.Properties["MinPasswordAge"].Value) - TimeSpan.FromSeconds((int)directoryEntry.Properties["PasswordAge"].Value));
//directoryEntry.Invoke("SetPassword", "Qwe12345"); directoryEntry.Invoke("SetPassword", "Qwe12345");
//directoryEntry.Properties["LockOutTime"].Value = 0; directoryEntry.Properties["LockOutTime"].Value = 0;
//directoryEntry.CommitChanges(); directoryEntry.CommitChanges();
directoryEntry.Close(); directoryEntry.Close();
//Console.WriteLine("Пароль установлен."); //Console.WriteLine("Пароль установлен.");
string[] str = {}; Main();
Main(str);
} }
private static void ShowDomainUserInfo() private static void ShowDomainUserInfo()
@@ -261,13 +269,37 @@ namespace domain_utility
StartPing(); StartPing();
} }
static void Main(string[] args) private static void OpenComputerCups()
{
Console.Write("\nВведите имя компьютера: ");
string input = Console.ReadLine().Trim();
if (input == string.Empty || input.Length == 0)
{
OpenComputerCups();
return;
}
for (int i = 0; i < computerNameRegex.GetLength(0); i++)
{
if (Regex.Match(input, computerNameRegex[i, 0]).Success)
{
Process.Start($"http://{computerNameRegex[i, 1]}{input.ToUpper()}:631/printers");
break;
}
}
Console.WriteLine();
Main();
}
static void Main()
{ {
Console.WriteLine("Выберите действие:\n" + Console.WriteLine("Выберите действие:\n" +
"1 - посмотреть информацию о пользователе\n" + "1 - посмотреть информацию о пользователе\n" +
"2 - посмотреть дату последней загрузки компьютера\n" + "2 - посмотреть дату последней загрузки компьютера (только Windows)\n" +
"3 - ping компьютера\n" + "3 - ping компьютера\n" +
"4 - сброс пароля локального администратора"); //"4 - сброс пароля локального администратора\n" +
"4 - открыть CUPS введенного компьютера");
string choice; string choice;
while(true) while(true)
{ {
@@ -280,11 +312,12 @@ namespace domain_utility
case 1: ShowDomainUserInfo(); break; case 1: ShowDomainUserInfo(); break;
case 2: ShowComputerBootupTime(); break; case 2: ShowComputerBootupTime(); break;
case 3: StartPing(); break; case 3: StartPing(); break;
case 4: ResetAdminPassword(); break; //case 4: ResetAdminPassword(); break;
case 4: OpenComputerCups(); break;
default: default:
{ {
Console.WriteLine("Неправильный выбор!"); Console.WriteLine("Неправильный выбор!");
Main(args); Main();
break; break;
} }
} }