Notice
Recent Posts
Recent Comments
관리 메뉴

안까먹을라고 쓰는 블로그

[C#] Network Ping Test 본문

Language/C#

[C#] Network Ping Test

YawnsDuzin 2012. 9. 11. 20:09

 

반응형


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
// Ping Test Values
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
PingReply reply;
string data = "";
string address = "192.168.0.59";
byte[] buffer;
int timeout = 500;
int RetryCnt = 1;
string Flag;
 
/// Ping Test Function
/// 
/// Ping Test Flag (true/false)
public Boolean Ping()
{
    try
    {
        Flag = "";
 
        options.DontFragment = true;
 
        buffer = Encoding.ASCII.GetBytes(data);
        reply = pingSender.Send(address, timeout, buffer, options);
 
         if (reply.Status == IPStatus.Success)
        {
            MessageBox.Show("PingTest_Success : " + reply.RoundtripTime);
            return true;
        }
        else
        {
            MessageBox.Show("PingTest_Failed : " + reply.RoundtripTime);
            return false;
        }
    }
    catch (Exception EX)
    {
        //MessageBox.Show(EX.ToString());
        return false;
    }
}
cs


반응형
Comments