Ping回复时间太长/不工作

本文关键字:工作 回复 时间 Ping | 更新日期: 2023-09-27 18:13:06

当使用Ping与PingReply相关来检查IP地址的状态以及它的端口和导入的文本列表时,您如何启动代码以跳过当前一个并移动到下一个?

    PingReply reply = ping.Send("IP", "PORT");
专门

    PingReply reply = ping.Send("174.69.75.251", "41968");

根本没有响应,它只是冻结应用程序,所以如果成功,您无法检查回复状态。


转到代理列表,我想检查它们是否有效,是否能够连接到webBrowser1控件,所以我有以下代码发送IP地址和端口请求,以检查它是否会接受连接。


这是循环和所有内容的全部代码,我添加了两个人建议的内容,并使用/* */排除了TCPClient,这里是按钮的代码:

private void button2_Click(object sender, EventArgs e)
{
    numberProx = Convert.ToInt32(textBox1.Lines.Length.ToString());
    proxyList = textBox1.Text.Split(new Char[] { ''n', ''r' }, StringSplitOptions.RemoveEmptyEntries);
    while (i < numberProx)
    {
        string currentProxy = proxyList[i++].ToString();
        try
        {/*
            TcpClient reply2 = new TcpClient();
            reply2.ConnectAsync(currentProxy.Split(':')[0],
                Convert.ToInt32(currentProxy.Split(':')[1]));
            if (reply2.Connected)
            {
                textBox2.AppendText(currentProxy + "'n");
            }
            else
            {
                textBox3.AppendText(currentProxy + "'n");
            }*/
            //PingReply reply = proxy.Send(currentProxy.Split(':')[0], Convert.ToInt32(currentProxy.Split(':')[1]));
            PingReply reply = await proxy.SendPingAsync("174.69.75.251", 5000);
            if (reply.Status == IPStatus.Success)
            {
                textBox2.AppendText(currentProxy + "'n");
            }
            else if (reply.Status == IPStatus.TimedOut)
            {
            }
            else if (reply.RoundtripTime >= 5000)
            {
                textBox3.AppendText(currentProxy + "'n");
            }
            else
            {
                textBox3.AppendText(currentProxy + "'n");
            }
        }
        catch (PingException ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
    }
}

这是所有的东西,包括循环和递增的整数,以匹配字符串[]中称为proxyList的代理数量。我想做的是看看代理是否能够在没有表单/UI冻结的情况下在webBrowser控件中工作。

Ping回复时间太长/不工作

ping请求无法测试应用端口。为此,您有telnet。

ping获取的参数。发送的是:

ping.Send('IP_ADDRESS', 'TIMEOUT');

就像MSDN文档中所说的

您可以使用Ping过载来指定超时。发送接受一个。这需要在超时之前等待的毫秒数。

如果你在一个UI应用程序中,这会导致你的UI线程冻结,你可以使用异步方法并等待结果。这将允许您的UI在发送请求时保持响应。