为了解某台机器是否可以被钉死;需要允许ICMP类型8 in和type 0 out。
public Boolean IsPingable()
{
Boolean icmpAllowed = false;
INetFwMgr mgr = (INetFwMgr)Activator.CreateInstance(NetFwMgrType);
Object allowedin8 = null;
Object restrictedin8 = null;
Object allowedout0 = null;
Object restrictedout0 = null;
mgr.IsIcmpTypeAllowed(NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4,"127.0.0.1", 0, out allowedin0, out restrictedin0);
mgr.IsIcmpTypeAllowed(NET_FW_IP_VERSION_.NET_FW_IP_VERSION_V4, "8.8.8.8", 8, out allowedout8, out restrictedout8);
if ((Boolean)allowedin0 && (Boolean)allowedout8)
{
icmpAllowed = true;
}
return icmpAllowed;
}
为什么不使用['System.Net.Networkinformation.Ping'(https://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping%28v=vs。 110%29.aspx?f = 255&MSPPError = -2147217396)class? –
@WaiHaLee可能会发布这个答案,因为它是答案? ;) – nozzleman