using System; using System.Net; using System.Net.Http; using System.Threading.Tasks; using System.Reflection; using System.Runtime.InteropServices; namespace dotnet_console { class Program { public static void Main(string[] args) { string version = typeof(RuntimeEnvironment).GetTypeInfo() .Assembly .GetCustomAttribute() .Version; Console.WriteLine("Assembly file version: " + version); Console.WriteLine(".NET Core version: " + GetNetCoreVersion()); string content = Task.Run(() => FetchString("http://motherfuckingwebsite.com", "/")).Result; Console.WriteLine("Content:"); Console.WriteLine(content); } public static async Task FetchString(string baseUrl, string path) { HttpClient client = new HttpClient(); client.BaseAddress = new Uri(baseUrl); Console.WriteLine("Starting request..."); HttpResponseMessage response = await client.GetAsync("/"); if (!response.IsSuccessStatusCode) throw new Exception("Request failed with status: " + response.StatusCode); Console.WriteLine("Response received."); string body = await response.Content.ReadAsStringAsync(); return body; } public static string GetNetCoreVersion() { var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly; var assemblyPath = assembly.CodeBase.Split(new[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries); int netCoreAppIndex = Array.IndexOf(assemblyPath, "Microsoft.NETCore.App"); if (netCoreAppIndex > 0 && netCoreAppIndex < assemblyPath.Length - 2) return assemblyPath[netCoreAppIndex + 1]; return null; } } }