예제 #1
0
        static async Task Main()
        {
            string speedTestServerURL = Environment.GetEnvironmentVariable("SpeedTestServerURL") ?? "http://localhost:8080/api/speedtest";
            string clientName         = Environment.GetEnvironmentVariable("ClientName") ?? "Env:ClientName";

            System.Console.WriteLine("v0.02 Client: " + clientName + " Target: " + speedTestServerURL);

            string publicIPv4       = "NoIP";
            bool   serverAccessible = false;

            try
            {
                publicIPv4 = await SpeedTestClient.GetPublicIPv4AddressAsync();

                await SpeedTestClient.ValidateAPIAccess(speedTestServerURL);

                serverAccessible = true;
                System.Console.WriteLine("Success - PublicIP: " + publicIPv4 + " Accessible: " + speedTestServerURL);
            }
            catch (Exception)
            {
                System.Console.WriteLine("Exception - PublicIP: " + publicIPv4 + " Accessible: " + serverAccessible);
                Environment.Exit(0);
            }

            client   = new SpeedTestClient();
            settings = client.GetSettings();

            //var servers = SelectServers();
            var bestServer = SelectDesiredServer(settings.Servers);

            foreach (var server in bestServer)
            {
                SpeedResult speedResult = new SpeedResult();
                speedResult.ServerName   = server.Sponsor;
                speedResult.LatencyMS    = server.Latency;
                speedResult.ServerID     = server.Id;
                speedResult.IP           = publicIPv4;
                speedResult.ClientName   = clientName;
                speedResult.DistanceKM   = Math.Round(server.Distance);
                speedResult.DownloadMbps = Math.Round(client.TestDownloadSpeed(server, settings.Download.ThreadsPerUrl) / 1024, 2);
                speedResult.UploadMbps   = Math.Round(client.TestUploadSpeed(server, settings.Upload.ThreadsPerUrl) / 1024, 2);
                await SpeedTestClient.SendSpeedResult(speedResult, speedTestServerURL);
            }
        }