示例#1
0
        public async Task PingAsync([Remainder] string message = null)
        {
            IPAddress IP;

            //Validates whether argument exists
            if (string.IsNullOrEmpty(message))
            {
                await ReplyAsync("Must supply an IP address.");
            }
            else
            {
                string ipAddr = "";

                //Custom ip for minecraft
                if (message == "minecraft")
                {
                    ipAddr = Config["MinecraftIP"];
                }
                else
                {
                    ipAddr = message;
                }

                //Validates given ip address
                if (!(IPAddress.TryParse(ipAddr.Split(':')[0], out IP)))
                {
                    await ReplyAsync(ipAddr + " is not a valid IP address.");
                }
                else
                {
                    //Ping the specified server
                    PingReply reply;
                    reply = PingService.PingRequest(ipAddr);

                    if (reply.Status == IPStatus.Success)
                    {
                        await ReplyAsync("PING SUCCESSFUL");
                        await ReplyAsync("Address: " + reply.Address.ToString());
                        await ReplyAsync("RoundTrip time: " + reply.RoundtripTime + "s");
                        await ReplyAsync("Time to live: " + reply.Options.Ttl);
                        await ReplyAsync("Don't fragment: " + reply.Options.DontFragment);
                        await ReplyAsync("Buffer size: " + reply.Buffer.Length);
                    }
                    else
                    {
                        await ReplyAsync("Address " + ipAddr + " is currently unreachable.");
                    }
                }
            }
        }