这个问题已经在这里有一个答案:
- 是否有可能写在C#中坪类,将Windows 8的地铁环境中运行? 1个回答
如何做到在WinRT中的现代UI应用程序的ICMP的ping?
平没有在WinRT中实现当前(请参阅相关的问题在这里 ),并在Silverlight为前策略:
- 使用WCF服务
- 调用JavaScript,然后调用ActiveX组件
- 放弃( 这里 )
瓦西里在这里使用HTTP来“平”使用StreamSocket支持使用TCP套接字网络通信的特定端口上的网络服务器。
也许Windows.Networking.Socket s是最高级别的API我,如果我想要写我自己的ICMP库WinRT的使用..
这实现使用的System.Net.Sockets使ICMP回应请求-在标准.NET
这 WinRT的示例使用Windows.Networking.Sockets.DatagramSocket类来创建一个UDP套接字。 我想,我需要的是原始套接字做ICMP。
这甚至可能在WinRT的沙箱ICMP的ping?
就像是:
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上