Сетевое программирование в .NET, страница 21

Console.WriteLine("\n  Statistics\n  " + line.Substring(1, 10) +

  "\n{0,-28}: {1}\n{2,-28}: {3}\n{4,-28}: {5}\n{6,-28}: {7}\n",

  "  Interfaces", st.NumberOfInterfaces,

  "  IP addresses", st.NumberOfIPAddresses,

  "  Routes", st.NumberOfRoutes,

  "  Default TTL", st.DefaultTtl);

Console.WriteLine("  Inbound Packet Data:\n  " + line.Substring(1, 20) +

  "\n{0,-28}: {1}\n{2,-28}: {3}\n{4,-28}: {5}\n" +

  "{6,-28}: {7}\n{8,-28}: {9}\n{10,-28}: {11}\n{12,-28}: {13}\n",

  "\tReceived", st.ReceivedPackets,

  "\tForwarded", st.ReceivedPacketsForwarded,

  "\tDelivered", st.ReceivedPacketsDelivered,

  "\tDiscarded", st.ReceivedPacketsDiscarded,

  "\tHeader Errors", st.ReceivedPacketsWithHeadersErrors,

  "\tAddress Errors", st.ReceivedPacketsWithAddressErrors,

  "\tUnknown Protocol Errors", st.ReceivedPacketsWithUnknownProtocol);

Console.WriteLine("  Outbound Packet Data:\n  " + line.Substring(1, 21) +

  "\n{0,-28}: {1}\n{2,-28}: {3}\n{4,-28}: {5}\n{6,-28}: {7}\n",

  "\tRequested", st.OutputPacketRequests,

  "\tDiscarded", st.OutputPacketsDiscarded,

  "\tNo Routing Discards", st.OutputPacketsWithNoRoute,

  "\tRouting Entry Discards", st.OutputPacketRoutingDiscards);

Console.WriteLine("  Reassembly Data:\n  " + line.Substring(1, 16) +

  "\n{0,-28}: {1}\n{2,-28}: {3}\n{4,-28}: {5}\n" +

  "{6,-28}: {7}\n{8,-28}: {9}\n",

  "\tReassembly Timeout", st.PacketReassemblyTimeout,

  "\tReassemblies Required", st.PacketReassembliesRequired,

  "\tPackets Reassembled", st.PacketsReassembled,

  "\tPackets Fragmented", st.PacketsFragmented,

  "\tFragment Failures", st.PacketFragmentFailures);

Анализ полученных данных потребует времени и заметных усилий и вы, если надо, выполните его самостоятельно а сейчас отметим, что свойство PacketReassemblyTimeout показывает количество миллисекунд (60 в нашем случае), в течение которых должны прийти все части (фрагменты) расчлененного пакета. Если это не случится, то пакет будет забракован.

Рассмотрим, как использовать метод GetIcmpV4Statistics класса IcmpV4Statistics, а также его многочисленные свойства для получения статистики прохождения сообщений. Вставьте следующий код после цикла прохода по адаптерам, так как он не зависит от типа адаптера.

IcmpV4Statistics s = p.GetIcmpV4Statistics();

string snt = "Sent", rec = "Received";

Console.WriteLine("\n\nICMP V4 Statistics:" + line.Substring(0, 20) +

  "\n{0,-28}{1}: {2,-10}{3}: {4,-10}\n" +

  "{5,-28}{6}: {7,-10}{8}: {9,-10}\n" +

  "{10,-28}{11}: {12,-10}{13}: {14,-10}\n" +

  "{15,-28}{16}: {17,-10}{18}: {19,-10}\n" +

  "{20,-28}{21}: {22,-10}{23}: {24,-10}\n" +

  "{25,-28}{26}: {27,-10}{28}: {29,-10}\n" +

  "{30,-28}{31}: {32,-10}{33}: {34,-10}\n" +

  "{35,-28}{36}: {37,-10}{38}: {39,-10}\n" +

  "{40,-28}{41}: {42,-10}{43}: {44,-10}\n" +

  "{45,-28}{46}: {47,-10}{48}: {49,-10}\n" +

  "{50,-28}{51}: {52,-10}{53}: {54,-10}\n" +

  "{55,-28}{56}: {57,-10}{58}: {59,-10}\n" +

  "{60,-28}{61}: {62,-10}{63}: {64,-10}\n",

  "  Messages", snt, s.MessagesSent, rec, s.MessagesReceived,

  "  Errors", snt, s.ErrorsSent, rec, s.ErrorsReceived,

  "  Echo Requests", snt, s.EchoRequestsSent, rec, s.EchoRequestsReceived,

  "  Echo Replies", snt, s.EchoRepliesSent, rec, s.EchoRepliesReceived,

  "  Destination Unreachables", snt, s.DestinationUnreachableMessagesSent, rec,

    s.DestinationUnreachableMessagesReceived,

  "  Source Quenches", snt, s.SourceQuenchesSent, rec, s.SourceQuenchesReceived,

  "  Redirects", snt, s.RedirectsSent, rec, s.RedirectsReceived,