C3032
2026-01-08 116ed6b584bbdb40c5b65e7cb57e039b6ae57800
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_SmartVisionCommon
{
    public class NetworkTester
    {
        public static async Task<bool> TestConnectionAsync(string host, int timeout = 3000)
        {
            try
            {
                using (var ping = new Ping())
                {
                    var reply = await ping.SendPingAsync(host, timeout);
                    AsyncLogHelper.Warn("相机IP:" + host + "通讯正常!");
                    return reply.Status == IPStatus.Success;
                }
            }
            catch
            {
                AsyncLogHelper.Warn("相机IP:" + host + "通讯异常!");
                return false;
            }
        }
 
        public static bool TestConnection(string host, int timeout = 3000)
        {
            try
            {
                using (var ping = new Ping())
                {
                    var reply = ping.Send(host, timeout);
                    return reply.Status == IPStatus.Success;
                }
            }
            catch
            {
                return false;
            }
        }
    }
}