コード例 #1
0
        List <ip_adress> GetIPListfromSIDR(string sNetwork, string Comm)
        {
            var ListIP = new List <ip_adress>();

            string[] parts = sNetwork.Split('.', '/');
            uint     ipnum = (Convert.ToUInt32(parts[0]) << 24) | (Convert.ToUInt32(parts[1]) << 16) | (Convert.ToUInt32(parts[2]) << 8) | Convert.ToUInt32(parts[3]);

            int  maskbits = Convert.ToInt32(parts[4]);
            uint mask     = 0xffffffff;

            mask <<= (32 - maskbits);

            uint startIP = ipnum & mask;
            uint endIP   = ipnum | (mask ^ 0xffffffff);

            for (var i = startIP + 1; i < endIP; i++)
            {
                byte[]    bytes = BitConverter.GetBytes(i);
                ip_adress newIp = new ip_adress(new[] { bytes[3], bytes[2], bytes[1], bytes[0] });
                newIp.Ping_Status = IPStatus.Unknown;
                newIp.Community   = Comm;
                ListIP.Add(newIp);
            }
            return(ListIP);
        }
コード例 #2
0
        async Task PingAndUpdateAsync(ip_adress ip)
        {
            Ping ping  = new Ping();
            var  reply = await ping.SendPingAsync(new IPAddress(ip.Adress), timeout);

            ip.Ping_Status = reply.Status;
            ping.Dispose();
        }
コード例 #3
0
        List <ip_adress> GetIPList(string ipFrom, string ipTo, string Comm)
        {
            List <ip_adress> ipList = new List <ip_adress>();

            byte[] firstBytesArray = IPAddress.Parse(ipFrom).GetAddressBytes();
            byte[] lastBytesArray  = IPAddress.Parse(ipTo).GetAddressBytes();
            Array.Reverse(firstBytesArray);
            Array.Reverse(lastBytesArray);
            uint first = BitConverter.ToUInt32(firstBytesArray, 0);
            uint last  = BitConverter.ToUInt32(lastBytesArray, 0);

            for (var i = first; i <= last; i++)
            {
                byte[]    bytes = BitConverter.GetBytes(i);
                ip_adress newIp = new ip_adress(new[] { bytes[3], bytes[2], bytes[1], bytes[0] });
                newIp.Ping_Status = IPStatus.Unknown;
                newIp.Community   = Comm;
                ipList.Add(newIp);
            }
            return(ipList);
        }
コード例 #4
0
        public NetworkIP(string ConnectionString)
        {
            Conn = ConnectionString;
            Hashtable IPP        = new Hashtable();
            DataTable IP_DataAdd = new DataTable();

            using (SqlConnection Conn = new SqlConnection(ConnectionString))
            {
                Conn.Open();
                string         sql = "SELECT Mask, A1, A2, A3, A4, B1, B2,B3,B4,Comm FROM SIS_IPList WHERE Del=0 ORDER BY id";
                SqlDataAdapter D_A = new SqlDataAdapter(sql, Conn);
                D_A.Fill(IP_DataAdd);
                Conn.Close();
            }

            foreach (DataRow R in IP_DataAdd.Rows)
            {
                string Comm = R["Comm"].ToString();
                string Mask = R["Mask"].ToString();
                string ip1  = string.Format("{0}.{1}.{2}.{3}", R["A1"], R["A2"], R["A3"], R["A4"]);
                string ip2  = string.Format("{0}.{1}.{2}.{3}", R["B1"], R["B2"], R["B3"], R["B4"]);

                List <ip_adress> IP_list = new List <ip_adress>();
                if (Mask == "")
                {
                    IP_list = GetIPList(ip1, ip2, Comm);
                }
                else
                {
                    IP_list = GetIPListfromSIDR(ip1 + '/' + Mask, Comm);
                }
                foreach (ip_adress ip in IP_list)
                {
                    if (!IPP.ContainsKey(ip.Adress))
                    {
                        IPP.Add(ip.Adress, ip.Community);
                    }
                }
            }

            DataTable IP_DataDel = new DataTable();

            using (SqlConnection Conn = new SqlConnection(ConnectionString))
            {
                Conn.Open();
                string         sql = "SELECT Mask, A1, A2, A3, A4, B1, B2,B3,B4,Comm FROM SIS_IPList WHERE Del=1 ORDER BY id";
                SqlDataAdapter D_A = new SqlDataAdapter(sql, Conn);
                D_A.Fill(IP_DataDel);
                Conn.Close();
            }
            foreach (DataRow R in IP_DataDel.Rows)
            {
                string Comm = R["Comm"].ToString();
                string Mask = R["Mask"].ToString();
                string ip1  = string.Format("{0}.{1}.{2}.{3}", R["A1"], R["A2"], R["A3"], R["A4"]);
                string ip2  = string.Format("{0}.{1}.{2}.{3}", R["B1"], R["B2"], R["B3"], R["B4"]);

                List <ip_adress> IP_list = new List <ip_adress>();
                if (Mask == "")
                {
                    IP_list = GetIPList(ip1, ip2, Comm);
                }
                else
                {
                    IP_list = GetIPListfromSIDR(ip1 + '/' + Mask, Comm);
                }
                foreach (ip_adress ip in IP_list)
                {
                    IPP.Remove(ip.Adress);
                }
            }
            ALL_Network.Clear();
            foreach (DictionaryEntry de in IPP)
            {
                ip_adress ip = new ip_adress((uint)de.Key);
                ip.Community = de.Value.ToString();
                ALL_Network.Add(ip);
            }
        }