그냥저냥

Ping 프로그램 코드 본문

Dev./C#

Ping 프로그램 코드

ex3llo 2016. 12. 28. 10:52
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;
using System.Net.NetworkInformation;
    
namespace PingSensorAppliance
{
    public partial class Form1 : Form
    {
        public ListViewItem li = null;
        public ListView lv = null;
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender,EventArgs e)
        {
            int i=0;
            string[] strArr_IP = {IP 목록};
            string[] strArr_Name = {호스트명};
            while(true)
            {
                try
                {
                    string[] arr = new string[3];
                    ListViewItem itm;
                    arr[0= strArr_IP[i];
                    arr[1= strArr_Name[i];
                    arr[2= pingConnect(strArr_IP[i]);
                    itm = new ListViewItem(arr)
                    listView1.Items.Add(itm);
                    i++;
                } catch { break; }
            }
        }
 
        public string pingConnect(string ip)
        {
            try
            {
                Ping pingSender = new Ping();
                PingOptions options = new PingOptions();
                options.DontFragment = true;
                string data = "a";
                byte[] buffer = Encoding.ASCII.GetBytes(data);
                int timeout = 120;
                PingReply reply = pingSender.Send(ip, timeout, buffer, options);
                if (reply.Status == IPStatus.Success)
                {
                    return "OK";
                }
                else 
                {
                    return "-";
                }
            } catch (Exception ex){
                return "Error";
            }
        }
    }
}
cs


'Dev. > C#' 카테고리의 다른 글

XML 파싱 및 파일명 변경  (0) 2016.12.28
Comments