Beispiel #1
0
        internal static IPGlobalStatisticsTable ParseIPv6GlobalStatisticsFromSnmp6File(string filePath)
        {
            // Read the remainder of statistics from snmp6.
            string          fileContents = ReadAllText(filePath);
            RowConfigReader reader       = new RowConfigReader(fileContents);

            return(new IPGlobalStatisticsTable()
            {
                InReceives = reader.GetNextValueAsInt64("Ip6InReceives"),
                InHeaderErrors = reader.GetNextValueAsInt64("Ip6InHdrErrors"),
                InAddressErrors = reader.GetNextValueAsInt64("Ip6InAddrErrors"),
                InUnknownProtocols = reader.GetNextValueAsInt64("Ip6InUnknownProtos"),
                InDiscards = reader.GetNextValueAsInt64("Ip6InDiscards"),
                InDelivers = reader.GetNextValueAsInt64("Ip6InDelivers"),
                ForwardedDatagrams = reader.GetNextValueAsInt64("Ip6OutForwDatagrams"),
                OutRequests = reader.GetNextValueAsInt64("Ip6OutRequests"),
                OutDiscards = reader.GetNextValueAsInt64("Ip6OutDiscards"),
                OutNoRoutes = reader.GetNextValueAsInt64("Ip6OutNoRoutes"),
                ReassemblyTimeout = reader.GetNextValueAsInt64("Ip6ReasmTimeout"),
                ReassemblyRequireds = reader.GetNextValueAsInt64("Ip6ReasmReqds"),
                ReassemblyOKs = reader.GetNextValueAsInt64("Ip6ReasmOKs"),
                ReassemblyFails = reader.GetNextValueAsInt64("Ip6ReasmFails"),
                FragmentOKs = reader.GetNextValueAsInt64("Ip6FragOKs"),
                FragmentFails = reader.GetNextValueAsInt64("Ip6FragFails"),
                FragmentCreates = reader.GetNextValueAsInt64("Ip6FragCreates"),
            });
        }
        public static UdpStatistics CreateUdpIPv6Statistics()
        {
            LinuxUdpStatistics stats = new LinuxUdpStatistics();

            string fileContents = File.ReadAllText(NetworkFiles.SnmpV6StatsFile);

            RowConfigReader reader = new RowConfigReader(fileContents);

            stats._inDatagrams  = reader.GetNextValueAsInt32("Udp6InDatagrams");
            stats._noPorts      = reader.GetNextValueAsInt32("Udp6NoPorts");
            stats._inErrors     = reader.GetNextValueAsInt32("Udp6InErrors");
            stats._outDatagrams = reader.GetNextValueAsInt32("Udp6OutDatagrams");
            stats._rcvbufErrors = reader.GetNextValueAsInt32("Udp6RcvbufErrors");
            stats._sndbufErrors = reader.GetNextValueAsInt32("Udp6SndbufErrors");
            stats._inCsumErrors = reader.GetNextValueAsInt32("Udp6InCsumErrors");

            // Parse the number of active connections out of /proc/net/sockstat6
            string       sockstatFile   = File.ReadAllText(NetworkFiles.Sockstat6File);
            int          indexOfUdp     = sockstatFile.IndexOf("UDP6:");
            int          endOfUdpLine   = sockstatFile.IndexOf(Environment.NewLine, indexOfUdp + 1);
            string       udpLineData    = sockstatFile.Substring(indexOfUdp, endOfUdpLine - indexOfUdp);
            StringParser sockstatParser = new StringParser(udpLineData, ' ');

            sockstatParser.MoveNextOrFail(); // Skip "UDP6:"
            sockstatParser.MoveNextOrFail(); // Skip: "inuse"
            stats._udpListeners = sockstatParser.ParseNextInt32();

            return(stats);
        }
Beispiel #3
0
        internal static string ParseDnsSuffixFromResolvConfFile(string data)
        {
            RowConfigReader rcr = new RowConfigReader(data);
            string          dnsSuffix;

            return(rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty);
        }
        private static string GetDnsSuffix()
        {
            string          data = File.ReadAllText(NetworkFiles.EtcResolvConfFile);
            RowConfigReader rcr  = new RowConfigReader(data);
            string          dnsSuffix;

            return(rcr.TryGetNextValue("search", out dnsSuffix) ? dnsSuffix : string.Empty);
        }
        internal static UdpGlobalStatisticsTable ParseUdpv6GlobalStatisticsFromSnmp6File(string filePath)
        {
            string          fileContents = File.ReadAllText(filePath);
            RowConfigReader reader       = new RowConfigReader(fileContents);

            return(new UdpGlobalStatisticsTable()
            {
                InDatagrams = reader.GetNextValueAsInt32("Udp6InDatagrams"),
                NoPorts = reader.GetNextValueAsInt32("Udp6NoPorts"),
                InErrors = reader.GetNextValueAsInt32("Udp6InErrors"),
                OutDatagrams = reader.GetNextValueAsInt32("Udp6OutDatagrams"),
                RcvbufErrors = reader.GetNextValueAsInt32("Udp6RcvbufErrors"),
                SndbufErrors = reader.GetNextValueAsInt32("Udp6SndbufErrors"),
                InCsumErrors = reader.GetNextValueAsInt32("Udp6InCsumErrors"),
            });
        }
        internal static UdpGlobalStatisticsTable ParseUdpv6GlobalStatisticsFromSnmp6File(string filePath)
        {
            string          fileContents  = File.ReadAllText(filePath);
            RowConfigReader reader        = new RowConfigReader(fileContents);
            int             udp6ErrorsIdx = fileContents.IndexOf("Udp6SndbufErrors", StringComparison.Ordinal);

            return(new UdpGlobalStatisticsTable()
            {
                InDatagrams = reader.GetNextValueAsInt64("Udp6InDatagrams"),
                NoPorts = reader.GetNextValueAsInt64("Udp6NoPorts"),
                InErrors = reader.GetNextValueAsInt64("Udp6InErrors"),
                OutDatagrams = reader.GetNextValueAsInt64("Udp6OutDatagrams"),
                RcvbufErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6RcvbufErrors"),
                SndbufErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6SndbufErrors"),
                InCsumErrors = udp6ErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt64("Udp6InCsumErrors"),
            });
        }
        public static IcmpV6Statistics CreateIcmpV6Statistics()
        {
            LinuxIcmpV6Statistics stats = new LinuxIcmpV6Statistics();

            string fileContents = File.ReadAllText(NetworkFiles.SnmpV6StatsFile);

            RowConfigReader reader = new RowConfigReader(fileContents);

            stats._inMsgs                    = reader.GetNextValueAsInt32("Icmp6InMsgs");
            stats._inErrors                  = reader.GetNextValueAsInt32("Icmp6InErrors");
            stats._outMsgs                   = reader.GetNextValueAsInt32("Icmp6OutMsgs");
            stats._outErrors                 = reader.GetNextValueAsInt32("Icmp6OutErrors");
            stats._inDestUnreachs            = reader.GetNextValueAsInt32("Icmp6InDestUnreachs");
            stats._inPktTooBigs              = reader.GetNextValueAsInt32("Icmp6InPktTooBigs");
            stats._inTimeExcds               = reader.GetNextValueAsInt32("Icmp6InTimeExcds");
            stats._inParmProblems            = reader.GetNextValueAsInt32("Icmp6InParmProblems");
            stats._inEchos                   = reader.GetNextValueAsInt32("Icmp6InEchos");
            stats._inEchoReplies             = reader.GetNextValueAsInt32("Icmp6InEchoReplies");
            stats._inGroupMembQueries        = reader.GetNextValueAsInt32("Icmp6InGroupMembQueries");
            stats._inGroupMembResponses      = reader.GetNextValueAsInt32("Icmp6InGroupMembResponses");
            stats._inGroupMembReductions     = reader.GetNextValueAsInt32("Icmp6InGroupMembReductions");
            stats._inRouterSolicits          = reader.GetNextValueAsInt32("Icmp6InRouterSolicits");
            stats._inRouterAdvertisements    = reader.GetNextValueAsInt32("Icmp6InRouterAdvertisements");
            stats._inNeighborSolicits        = reader.GetNextValueAsInt32("Icmp6InNeighborSolicits");
            stats._inNeighborAdvertisements  = reader.GetNextValueAsInt32("Icmp6InNeighborAdvertisements");
            stats._inRedirects               = reader.GetNextValueAsInt32("Icmp6InRedirects");
            stats._outDestUnreachs           = reader.GetNextValueAsInt32("Icmp6OutDestUnreachs");
            stats._outPktTooBigs             = reader.GetNextValueAsInt32("Icmp6OutPktTooBigs");
            stats._outTimeExcds              = reader.GetNextValueAsInt32("Icmp6OutTimeExcds");
            stats._outParmProblems           = reader.GetNextValueAsInt32("Icmp6OutParmProblems");
            stats._outEchos                  = reader.GetNextValueAsInt32("Icmp6OutEchos");
            stats._outEchoReplies            = reader.GetNextValueAsInt32("Icmp6OutEchoReplies");
            stats._outInGroupMembQueries     = reader.GetNextValueAsInt32("Icmp6OutGroupMembQueries");
            stats._outGroupMembResponses     = reader.GetNextValueAsInt32("Icmp6OutGroupMembResponses");
            stats._outGroupMembReductions    = reader.GetNextValueAsInt32("Icmp6OutGroupMembReductions");
            stats._outRouterSolicits         = reader.GetNextValueAsInt32("Icmp6OutRouterSolicits");
            stats._outRouterAdvertisements   = reader.GetNextValueAsInt32("Icmp6OutRouterAdvertisements");
            stats._outNeighborSolicits       = reader.GetNextValueAsInt32("Icmp6OutNeighborSolicits");
            stats._outNeighborAdvertisements = reader.GetNextValueAsInt32("Icmp6OutNeighborAdvertisements");
            stats._outRedirects              = reader.GetNextValueAsInt32("Icmp6OutRedirects");

            return(stats);
        }
Beispiel #8
0
        public static Icmpv6StatisticsTable ParseIcmpv6FromSnmp6File(string filePath)
        {
            string          fileContents      = ReadAllText(filePath);
            RowConfigReader reader            = new RowConfigReader(fileContents);
            bool            hasIcmp6OutErrors = fileContents.Contains("Icmp6OutErrors");

            return(new Icmpv6StatisticsTable()
            {
                InMsgs = reader.GetNextValueAsInt64("Icmp6InMsgs"),
                InErrors = reader.GetNextValueAsInt64("Icmp6InErrors"),
                OutMsgs = reader.GetNextValueAsInt64("Icmp6OutMsgs"),
                OutErrors = hasIcmp6OutErrors ? reader.GetNextValueAsInt64("Icmp6OutErrors") : 0,
                InDestUnreachs = reader.GetNextValueAsInt64("Icmp6InDestUnreachs"),
                InPktTooBigs = reader.GetNextValueAsInt64("Icmp6InPktTooBigs"),
                InTimeExcds = reader.GetNextValueAsInt64("Icmp6InTimeExcds"),
                InParmProblems = reader.GetNextValueAsInt64("Icmp6InParmProblems"),
                InEchos = reader.GetNextValueAsInt64("Icmp6InEchos"),
                InEchoReplies = reader.GetNextValueAsInt64("Icmp6InEchoReplies"),
                InGroupMembQueries = reader.GetNextValueAsInt64("Icmp6InGroupMembQueries"),
                InGroupMembResponses = reader.GetNextValueAsInt64("Icmp6InGroupMembResponses"),
                InGroupMembReductions = reader.GetNextValueAsInt64("Icmp6InGroupMembReductions"),
                InRouterSolicits = reader.GetNextValueAsInt64("Icmp6InRouterSolicits"),
                InRouterAdvertisements = reader.GetNextValueAsInt64("Icmp6InRouterAdvertisements"),
                InNeighborSolicits = reader.GetNextValueAsInt64("Icmp6InNeighborSolicits"),
                InNeighborAdvertisements = reader.GetNextValueAsInt64("Icmp6InNeighborAdvertisements"),
                InRedirects = reader.GetNextValueAsInt64("Icmp6InRedirects"),
                OutDestUnreachs = reader.GetNextValueAsInt64("Icmp6OutDestUnreachs"),
                OutPktTooBigs = reader.GetNextValueAsInt64("Icmp6OutPktTooBigs"),
                OutTimeExcds = reader.GetNextValueAsInt64("Icmp6OutTimeExcds"),
                OutParmProblems = reader.GetNextValueAsInt64("Icmp6OutParmProblems"),
                OutEchos = reader.GetNextValueAsInt64("Icmp6OutEchos"),
                OutEchoReplies = reader.GetNextValueAsInt64("Icmp6OutEchoReplies"),
                OutInGroupMembQueries = reader.GetNextValueAsInt64("Icmp6OutGroupMembQueries"),
                OutGroupMembResponses = reader.GetNextValueAsInt64("Icmp6OutGroupMembResponses"),
                OutGroupMembReductions = reader.GetNextValueAsInt64("Icmp6OutGroupMembReductions"),
                OutRouterSolicits = reader.GetNextValueAsInt64("Icmp6OutRouterSolicits"),
                OutRouterAdvertisements = reader.GetNextValueAsInt64("Icmp6OutRouterAdvertisements"),
                OutNeighborSolicits = reader.GetNextValueAsInt64("Icmp6OutNeighborSolicits"),
                OutNeighborAdvertisements = reader.GetNextValueAsInt64("Icmp6OutNeighborAdvertisements"),
                OutRedirects = reader.GetNextValueAsInt64("Icmp6OutRedirects")
            });
        }
Beispiel #9
0
        public static Icmpv6StatisticsTable ParseIcmpv6FromSnmp6File(string filePath)
        {
            string          fileContents      = File.ReadAllText(filePath);
            RowConfigReader reader            = new RowConfigReader(fileContents);
            int             Icmp6OutErrorsIdx = fileContents.IndexOf("Icmp6OutErrors", StringComparison.Ordinal);

            return(new Icmpv6StatisticsTable()
            {
                InMsgs = reader.GetNextValueAsInt32("Icmp6InMsgs"),
                InErrors = reader.GetNextValueAsInt32("Icmp6InErrors"),
                OutMsgs = reader.GetNextValueAsInt32("Icmp6OutMsgs"),
                OutErrors = Icmp6OutErrorsIdx == -1 ? 0 : reader.GetNextValueAsInt32("Icmp6OutErrors"),
                InDestUnreachs = reader.GetNextValueAsInt32("Icmp6InDestUnreachs"),
                InPktTooBigs = reader.GetNextValueAsInt32("Icmp6InPktTooBigs"),
                InTimeExcds = reader.GetNextValueAsInt32("Icmp6InTimeExcds"),
                InParmProblems = reader.GetNextValueAsInt32("Icmp6InParmProblems"),
                InEchos = reader.GetNextValueAsInt32("Icmp6InEchos"),
                InEchoReplies = reader.GetNextValueAsInt32("Icmp6InEchoReplies"),
                InGroupMembQueries = reader.GetNextValueAsInt32("Icmp6InGroupMembQueries"),
                InGroupMembResponses = reader.GetNextValueAsInt32("Icmp6InGroupMembResponses"),
                InGroupMembReductions = reader.GetNextValueAsInt32("Icmp6InGroupMembReductions"),
                InRouterSolicits = reader.GetNextValueAsInt32("Icmp6InRouterSolicits"),
                InRouterAdvertisements = reader.GetNextValueAsInt32("Icmp6InRouterAdvertisements"),
                InNeighborSolicits = reader.GetNextValueAsInt32("Icmp6InNeighborSolicits"),
                InNeighborAdvertisements = reader.GetNextValueAsInt32("Icmp6InNeighborAdvertisements"),
                InRedirects = reader.GetNextValueAsInt32("Icmp6InRedirects"),
                OutDestUnreachs = reader.GetNextValueAsInt32("Icmp6OutDestUnreachs"),
                OutPktTooBigs = reader.GetNextValueAsInt32("Icmp6OutPktTooBigs"),
                OutTimeExcds = reader.GetNextValueAsInt32("Icmp6OutTimeExcds"),
                OutParmProblems = reader.GetNextValueAsInt32("Icmp6OutParmProblems"),
                OutEchos = reader.GetNextValueAsInt32("Icmp6OutEchos"),
                OutEchoReplies = reader.GetNextValueAsInt32("Icmp6OutEchoReplies"),
                OutInGroupMembQueries = reader.GetNextValueAsInt32("Icmp6OutGroupMembQueries"),
                OutGroupMembResponses = reader.GetNextValueAsInt32("Icmp6OutGroupMembResponses"),
                OutGroupMembReductions = reader.GetNextValueAsInt32("Icmp6OutGroupMembReductions"),
                OutRouterSolicits = reader.GetNextValueAsInt32("Icmp6OutRouterSolicits"),
                OutRouterAdvertisements = reader.GetNextValueAsInt32("Icmp6OutRouterAdvertisements"),
                OutNeighborSolicits = reader.GetNextValueAsInt32("Icmp6OutNeighborSolicits"),
                OutNeighborAdvertisements = reader.GetNextValueAsInt32("Icmp6OutNeighborAdvertisements"),
                OutRedirects = reader.GetNextValueAsInt32("Icmp6OutRedirects")
            });
        }
Beispiel #10
0
        internal static List <IPAddress> ParseDnsAddressesFromResolvConfFile(string data)
        {
            // Parse /etc/resolv.conf for all of the "nameserver" entries.
            // These are the DNS servers the machine is configured to use.
            // On OSX, this file is not directly used by most processes for DNS
            // queries/routing, but it is automatically generated instead, with
            // the machine's DNS servers listed in it.
            RowConfigReader  rcr       = new RowConfigReader(data);
            List <IPAddress> addresses = new List <IPAddress>();

            while (rcr.TryGetNextValue("nameserver", out string?addressString))
            {
                if (IPAddress.TryParse(addressString, out IPAddress? parsedAddress))
                {
                    addresses.Add(parsedAddress);
                }
            }

            return(addresses);
        }
        private static IPAddressCollection GetDnsAddresses()
        {
            // Parse /etc/resolv.conf for all of the "nameserver" entries.
            // These are the DNS servers the machine is configured to use.
            // On OSX, this file is not directly used by most processes for DNS
            // queries/routing, but it is automatically generated instead, with
            // the machine's DNS servers listed in it.
            string                      data      = File.ReadAllText(NetworkFiles.EtcResolvConfFile);
            RowConfigReader             rcr       = new RowConfigReader(data);
            InternalIPAddressCollection addresses = new InternalIPAddressCollection();

            string addressString = null;

            while (rcr.TryGetNextValue("nameserver", out addressString))
            {
                IPAddress parsedAddress;
                if (IPAddress.TryParse(addressString, out parsedAddress))
                {
                    addresses.InternalAdd(parsedAddress);
                }
            }

            return(addresses);
        }
        /// <summary>
        /// Constructs an IPGlobalStatistics object from the snmp6 stats file.
        /// </summary>
        public static LinuxIPGlobalStatistics CreateIPv6Statistics()
        {
            LinuxIPGlobalStatistics stats = new LinuxIPGlobalStatistics();

            // /proc/sys/net/ipv6/conf/default/forwarding
            string path = Path.Combine(NetworkFiles.Ipv4ConfigFolder,
                                       NetworkFiles.DefaultNetworkInterfaceFileName,
                                       NetworkFiles.ForwardingFileName);

            stats._forwarding = int.Parse(File.ReadAllText(path)) == 1;

            // snmp6 does not include Default TTL info. Read it from snmp.
            string       snmp4FileContents = File.ReadAllText(NetworkFiles.SnmpV4StatsFile);
            int          firstIpHeader     = snmp4FileContents.IndexOf("Ip:");
            int          secondIpHeader    = snmp4FileContents.IndexOf("Ip:", firstIpHeader + 1);
            int          endOfSecondLine   = snmp4FileContents.IndexOf(Environment.NewLine, secondIpHeader);
            string       ipData            = snmp4FileContents.Substring(secondIpHeader, endOfSecondLine - secondIpHeader);
            StringParser parser            = new StringParser(ipData, ' ');

            parser.MoveNextOrFail(); // Skip Ip:
            // According to RFC 1213, "1" indicates "acting as a gateway". "2" indicates "NOT acting as a gateway".
            parser.MoveNextOrFail(); // Skip forwarding
            stats._defaultTtl = parser.ParseNextInt32();

            // Read the remainder of statistics from snmp6.
            string          fileContents = File.ReadAllText(NetworkFiles.SnmpV6StatsFile);
            RowConfigReader reader       = new RowConfigReader(fileContents);

            stats._inReceives          = reader.GetNextValueAsInt32("Ip6InReceives");
            stats._inHeaderErrors      = reader.GetNextValueAsInt32("Ip6InHdrErrors");
            stats._inAddressErrors     = reader.GetNextValueAsInt32("Ip6InAddrErrors");
            stats._inUnknownProtocols  = reader.GetNextValueAsInt32("Ip6InUnknownProtos");
            stats._inDiscards          = reader.GetNextValueAsInt32("Ip6InDiscards");
            stats._inDelivers          = reader.GetNextValueAsInt32("Ip6InDelivers");
            stats._forwardedDatagrams  = reader.GetNextValueAsInt32("Ip6OutForwDatagrams");
            stats._outRequests         = reader.GetNextValueAsInt32("Ip6OutRequests");
            stats._outDiscards         = reader.GetNextValueAsInt32("Ip6OutDiscards");
            stats._outNoRoutes         = reader.GetNextValueAsInt32("Ip6OutNoRoutes");
            stats._reassemblyTimeout   = reader.GetNextValueAsInt32("Ip6ReasmTimeout");
            stats._reassemblyRequireds = reader.GetNextValueAsInt32("Ip6ReasmReqds");
            stats._reassemblyOKs       = reader.GetNextValueAsInt32("Ip6ReasmOKs");
            stats._reassemblyFails     = reader.GetNextValueAsInt32("Ip6ReasmFails");
            stats._fragmentOKs         = reader.GetNextValueAsInt32("Ip6FragOKs");
            stats._fragmentFails       = reader.GetNextValueAsInt32("Ip6FragFails");
            stats._fragmentCreates     = reader.GetNextValueAsInt32("Ip6FragCreates");

            string routeFile = ReadProcConfigFile(NetworkFiles.Ipv6RouteFile);

            stats._numRoutes = CountOccurences(Environment.NewLine, routeFile);

            int interfaceCount = 0;
            var files          = new DirectoryInfo(NetworkFiles.Ipv6ConfigFolder).GetFiles();

            foreach (var file in files)
            {
                if (file.Name != NetworkFiles.AllNetworkInterfaceFileName &&
                    file.Name != NetworkFiles.DefaultNetworkInterfaceFileName)
                {
                    interfaceCount++;
                }
            }
            stats._numInterfaces  = interfaceCount;
            stats._numIPAddresses = GetNumIPAddresses();
            return(stats);
        }