2012-10-16 5 views
3

WinRT Modern UI 응용 프로그램에서 ICMP 핑을 수행하는 방법은 무엇입니까?WinRT의 ICMP Ping - 가능합니까?

  • 다음 ActiveX 구성 요소를
  • 내놔 호출하는 WCF 서비스
  • 전화 자바 스크립트를 사용

    핑은 현재와 실버 존재의 이전 전략 (관련 질문 here 참조) WinRT에서 구현되지 않습니다 최대 (here)

바실리 here 사용하여 특정 포트에서 웹 서버 '핑'에 HTTP를 사용 TCP 소켓을 사용하여 네트워크 통신을 지원하는 StreamSocket입니다.

아마도 Windows.Networking.Socket

This 구현은 ICMP 에코 요청을하려면 System.Net.Sockets을 사용 .. 내가 WinRT에 대한 내 자신의 ICMP 라이브러리를 작성하려는 경우 사용해야하는 가장 높은 수준의 API입니다 - 표준 .NET

This WinRT 샘플에서는 Windows.Networking.Sockets.DatagramSocket 클래스를 사용하여 UDP 소켓을 만듭니다. ICMP를 할 원시 소켓이 필요하다고 생각합니다.

WinRT 샌드 박스에서 ICMP 핑으로이 작업을 수행 할 수 있습니까?

답변

1

뭔가처럼 여기

try 
      { 
       using (var tcpClient = new StreamSocket()) 
       { 
        await tcpClient.ConnectAsync(
         new Windows.Networking.HostName(HostName), 
         PortNumber, 
         SocketProtectionLevel.PlainSocket); 

        var localIp = tcpClient.Information.LocalAddress.DisplayName; 
        var remoteIp = tcpClient.Information.RemoteAddress.DisplayName; 

        ConnectionAttemptInformation = String.Format("Success, remote server contacted at IP address {0}", 
                   remoteIp); 
        tcpClient.Dispose(); 
       } 
      } 
      catch (Exception ex) 
      { 
       if (ex.HResult == -2147013895) 
       { 
        ConnectionAttemptInformation = "Error: No such host is known"; 
       } 
       else if (ex.HResult == -2147014836) 
       { 
        ConnectionAttemptInformation = "Error: Timeout when connecting (check hostname and port)"; 
       } 
       else 
       { 
        ConnectionAttemptInformation = "Error: Exception returned from network stack: " + ex.Message; 
       } 
      } 
      finally 
      { 
       ConnectionInProgress = false; 
      } 

전체 소스 : github

+0

감사합니다 - 나는 StreamSocket은 TCP 전송 레벨을 믿고, 그래서 ICMP 핑을 만드는 일을 할 수 없습니다. –

+0

실제로 Ping을 사용하거나 단순히 기능을 복제해야합니까? –

+3

예 ICMP 핑을 사용해야합니다 :-) 불행히도 포트 80 또는 443 요청으로는 충분하지 않습니다. –