-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (62 loc) · 3.29 KB
/
Program.cs
File metadata and controls
72 lines (62 loc) · 3.29 KB
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
using System;
using System.IO;
using System.Text;
class ApacheLogGenerator
{
static void Main(string[] args)
{
// Настройки
string filePath = @"E:\Logs\access.log"; // Укажи свой путь
long targetSizeInBytes = 10L * 1024 * 1024 * 1024; // 10 ГБ
// Данные для рандомизации
string[] ipAddresses = { "192.168.1.1", "10.0.0.15", "172.16.254.1", "8.8.8.8", "45.33.22.11" };
string[] methods = { "GET", "POST", "PUT", "DELETE" };
string[] resources = { "/index.html", "/api/v1/login", "/images/logo.png", "/css/style.css", "/products/123" };
string[] protocols = { "HTTP/1.1", "HTTP/2.0" };
int[] statuses = { 200, 201, 301, 404, 500 };
Random random = new Random();
long currentSize = 0;
Console.WriteLine($"Начинаю генерацию файла: {filePath}");
Console.WriteLine("Это может занять несколько минут...");
try
{
// Создаем директорию, если она не существует
string directory = Path.GetDirectoryName(filePath);
if (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
// Используем большой буфер (64 КБ) для ускорения записи
using (StreamWriter writer = new StreamWriter(filePath, false, Encoding.UTF8, 65536))
{
while (currentSize < targetSizeInBytes)
{
// Собираем строку в формате:
// IP - - [Date] "Method Resource Protocol" Status Bytes
string ip = ipAddresses[random.Next(ipAddresses.Length)];
string date = DateTime.Now.ToString("dd/MMM/yyyy:HH:mm:ss +0000");
string method = methods[random.Next(methods.Length)];
string resource = resources[random.Next(resources.Length)];
string protocol = protocols[random.Next(protocols.Length)];
int status = statuses[random.Next(statuses.Length)];
int bytes = random.Next(100, 5000);
string logEntry = $"{ip} - - [{date}] \"{method} {resource} {protocol}\" {status} {bytes}";
writer.WriteLine(logEntry);
// Увеличиваем счетчик размера (учитываем символы новой строки)
currentSize += Encoding.UTF8.GetByteCount(logEntry) + Environment.NewLine.Length;
// Вывод прогресса каждые 500 МБ
if (currentSize % (512 * 1024 * 1024) < 500)
{
double progress = (double)currentSize / targetSizeInBytes * 100;
Console.WriteLine($"Прогресс: {progress:F2}% ({currentSize / 1024 / 1024} МБ)");
}
}
}
Console.WriteLine("\nГотово! Файл успешно создан.");
}
catch (Exception ex)
{
Console.WriteLine($"Ошибка: {ex.Message}");
}
}
}