My Name is Kay....

DIY , 먹방 , 개발 , 육아 , 여행 좋아합니다.
AdBlock 사용시 화면이 정상적으로 노출되지 않습니다.
포스팅 관련 문의 및 개발 문의는 Email : wkzkfmxksi@gmail.com

추가 포스팅이 이뤄지지 않는 블로그입니다. 문의는 wkzkfmxksi@gmail.com 으로 연락주세요.
kay
조회 수 2582 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄 첨부

웹사이트 모니터링용 프로그램을 찾다가 간단한 소스가 있어 만들어보았습니다.

만들었다기 보다..응용하여 쬐금 보완했습니다.



app.config 내에 셋팅된 Url 페이지를 호출하여 StatusCode 를 분석합니다.

상태 값에 따라 200 코드 ( 정상 )이 아닌 경우 알립니다.


http Status Code 에 따라 각각의 코드와 상태 값을 반환하는 기능으로 만들어졌습니다.

  • 원격 서버에서 (404) 찾을 수 없음 오류를 반환했습니다 .
  • 작업시간이 초과되었습니다.


Visual Studio 2008 C# 으로 만들었으며

일부 소스는 참고 Url의 소스를 참고하여 수정하였습니다.


주요 코드   ( 전체 프로젝트 소스 : WebSiteMonitoring.zip )


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Specialized;
using System.Web;
using System.Net;
using System.Net.Mail; 


namespace WebSiteMonitoring
{
    internal static class website
    {
        internal static void siteUrlCheck(string siteUrl)
        {
            try
            {
                var webRequest = HttpWebRequest.Create(siteUrl) as HttpWebRequest;
                webRequest.Method = WebRequestMethods.Http.Get;

                using (var webResponse = webRequest.GetResponse() as HttpWebResponse)
                {

                    if ((int)webResponse.StatusCode != 200)
                    {
                        Console.Write(siteUrl + ":" + (int)webResponse.StatusCode + Environment.NewLine);

                        // E-mail , SMS , Log 등등...비정상 처리 
                        //SmtpClient client = new SmtpClient();
                        //client.Host = "SMTP 서버";
                        //client.Timeout = 10000;
                        //client.DeliveryMethod = SmtpDeliveryMethod.Network;
                        //client.UseDefaultCredentials = false;
                        //client.Credentials = new System.Net.NetworkCredential("인증ID", "인증PW");

                        //MailMessage mm = new MailMessage("From 주소", "to 주소", "제목", urlsToPing + Environment.NewLine + ((int)webResponse.StatusCode).ToString());
                        //mm.BodyEncoding = UTF8Encoding.UTF8;
                        //mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                        //client.Send(mm);

                    }
                    else
                    {
                        Console.Write(siteUrl + ":" + (int)webResponse.StatusCode + Environment.NewLine);
                        // E-mail , SMS , Log 등등...정상 처리 
                    }
                }
            }
            catch (WebException ex)
            {
                Console.Write(ex.Message);
               // 에러 발생 시 코드 
            }
        }
 
    }
}


http Status Code : https://ko.wikipedia.org/wiki/HTTP_상태_코드

참고 Url : http://tekprolixity.blogspot.kr/2013/10/simple-website-monitor-with-c.html?showComment=1439886984065#c8181182623190154426

  1. [2015/07/30] C# SMTP 서버를 이용한 메일 발송 by kay (1406) *1
  2. [2015/04/29] 서버 모니터링 와탭 - whatap by kay (1795)
  3. [2014/10/14] C# 엑셀데이터 읽어서 디비에 저장 by kay (5124)
  4. [2014/10/14] C# 소수점 지정 by kay (1834)
  5. [2013/12/23] appSettings 값 추가하기 , 읽어오기 , 값 존재 유무 체크 by kay (5236)
?