Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net.Http;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- private const int DefaultTimeout = 15000;
- private static readonly HttpClient httpClient = new HttpClient { Timeout = TimeSpan.FromMilliseconds(DefaultTimeout) };
- static async Task Main()
- {
- Console.WriteLine("Choose the language you want to check:");
- Console.WriteLine("1. Arabic");
- Console.WriteLine("2. English");
- Console.WriteLine("3. Spanish");
- Console.WriteLine("4. Chinese");
- if (!int.TryParse(Console.ReadLine(), out int languageChoice) || languageChoice < 1 || languageChoice > 4)
- {
- Console.WriteLine("Invalid language choice.");
- return;
- }
- string baseUrl = GetBaseUrl(languageChoice);
- int endNumber = GetEndNumber(languageChoice);
- string namefile = GetFileName(languageChoice);
- using (var writer = new StreamWriter(namefile))
- {
- for (int i = 0; i <= endNumber; i++)
- {
- string executableUrl = $"{baseUrl}{i:D4}.exe";
- string zipUrl = $"{baseUrl}{i:D4}.zip";
- bool isExecutableResponseReceived = await IsReachableUrlAsync(executableUrl);
- bool isZipResponseReceived = await IsReachableUrlAsync(zipUrl);
- if (isExecutableResponseReceived || isZipResponseReceived)
- {
- string receivedUrl = isExecutableResponseReceived ? executableUrl : zipUrl;
- Console.WriteLine($"Received a response from the URL: {receivedUrl}");
- writer.WriteLine(receivedUrl);
- }
- else
- {
- Console.WriteLine($"No response received for {i:D4}");
- }
- }
- }
- Console.WriteLine("Finished checking URLs.");
- Console.ReadKey();
- }
- private static string GetFileName(int languageChoice)
- {
- switch (languageChoice)
- {
- case 1: return "Arabic Client Links.txt";
- case 2: return "English Client Links.txt";
- case 3: return "Spanish Client Links.txt";
- case 4: return "Chinese Client Links.txt";
- default: throw new ArgumentException("Invalid language choice.");
- }
- }
- private static string GetBaseUrl(int languageChoice)
- {
- switch (languageChoice)
- {
- case 1: return "https://arconquer.download.99.com/ar_zf/Arabic_Conquer_v";
- case 2: return "https://codl.99.com/en_zf/Conquer_v";
- case 3: return "https://codl.99.com/sp_zf/Conquista_v";
- case 4: return "https://zfcdndownload.99.com/zf/zf_";
- default: throw new ArgumentException("Invalid language choice.");
- }
- }
- private static int GetEndNumber(int languageChoice)
- {
- switch (languageChoice)
- {
- case 1: return 10000;
- case 2: return 10000;
- case 3: return 10000;
- case 4: return 10000;
- default: throw new ArgumentException("Invalid language choice.");
- }
- }
- private static async Task<bool> IsReachableUrlAsync(string url)
- {
- try
- {
- using (var response = await httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
- {
- return response.IsSuccessStatusCode;
- }
- }
- catch (HttpRequestException)
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement