Ping C# 源码

时间:2015-11-09 16:02:35
【文件属性】:

文件名称:Ping C# 源码

文件大小:8KB

文件格式:CS

更新时间:2015-11-09 16:02:35

C# Ping

C@ Ping ICMP 协议 public string PingHost(string host) { // 声明 IPHostEntry IPHostEntry ServerHE, fromHE; int nBytes = 0; int dwStart = 0, dwStop = 0; //初始化ICMP的Socket Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Icmp); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000); // 得到Server EndPoint try { ServerHE = Dns.GetHostByName(host); } catch (Exception) { return "没有发现主机"; } // 把 Server IP_EndPoint转换成EndPoint IPEndPoint ipepServer = new IPEndPoint(ServerHE.AddressList[0], 0); EndPoint epServer = (ipepServer); // 设定客户机的接收Endpoint fromHE = Dns.GetHostByName(Dns.GetHostName()); IPEndPoint ipEndPointFrom = new IPEndPoint(fromHE.AddressList[0], 0); EndPoint EndPointFrom = (ipEndPointFrom); int PacketSize = 0; IcmpPacket packet = new IcmpPacket();


网友评论

  • 用处不大,而且还有问题