- 博客(0)
- 资源 (1)
空空如也
Ping C# 源码
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();
2012-10-19
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人