示例#1
0
        private void calcSubnet()
        {
            if (cbUseSubnet.Checked == true)
            {
                if (IpHelpers.isValidIP(tbSubnetMask.Text))
                {
                    btnStart.Enabled       = true;
                    tbIPStart.Enabled      = true;
                    tbIPEndNetwork.Enabled = true;
                    tbIPEnd.Enabled        = true;

                    ipSeg          = new IPSegment(tbIPStart.Text, tbSubnetMask.Text);
                    tbIPStart.Text = ipSeg.FirstIP.ToIpString();

                    tbIPEndNetwork.Text     = IPFirstPart(ipSeg.LastIP.ToIpString());
                    tbIPEnd.Text            = IPLastPart(ipSeg.LastIP.ToIpString());
                    tbIPEndNetwork.ReadOnly = false;
                }
                else
                {
                    btnStart.Enabled       = false;
                    tbIPStart.Enabled      = false;
                    tbIPEndNetwork.Enabled = false;
                    tbIPEnd.Enabled        = false;
                }
            }
        }
示例#2
0
        private bool CheckFirstIP()
        {
            string startIP = tbIPStart.Text;

            if (IpHelpers.isValidIP(startIP) && startIP != "")
            {
                if (ipSeg.isInNetwork(startIP) == true)
                {
                    firstIP = startIP;
                    return(true);
                }
                return(false);
            }
            return(false);
        }
示例#3
0
        private bool CheckLastIP()
        {
            string endIP = tbIPEndNetwork.Text + tbIPEnd.Text;

            if (IpHelpers.isValidIP(endIP) && tbIPEndNetwork.Text != "" && tbIPEnd.Text != "")
            {
                if (ipSeg.isInNetwork(endIP) == true)
                {
                    lastIP = endIP;
                    return(true);
                }
                return(false);
            }
            return(false);
        }
示例#4
0
        private void GetHosts()
        {
            ips.Clear(); //Clear Hosts List
            if (IpHelpers.isValidIP(tbIPStart.Text) == true && IpHelpers.isValidIP(tbIPEnd.Text) && cbUseSubnet.Checked == false)
            {
                string ipStart    = tbIPStart.Text;
                string ipEnd      = tbIPEnd.Text;
                string ipNet      = IPFirstPart(ipStart);
                int    ipStartSub = Convert.ToInt32(IPLastPart(ipStart));
                int    ipEndSub   = Convert.ToInt32(ipEnd);

                if (ipStartSub <= ipEndSub)
                {
                    for (int i = ipStartSub; i <= ipEndSub; i++)
                    {
                        IPAddress newIP   = IPAddress.Parse(ipNet + i.ToString());
                        Host      newHost = new Host();
                        newHost.IP_Address   = newIP;
                        newHost.CountChecks  = 0;
                        newHost.RunningCheck = false;
                        ips.Add(newHost);
                    }
                }
            }
            if (IpHelpers.isValidIP(tbIPStart.Text) == true && cbUseSubnet.Checked == true)
            {
                foreach (var host in ipSeg.Hosts())
                {
                    if (host >= IpHelpers.ParseIp(firstIP) && host <= IpHelpers.ParseIp(lastIP))
                    {
                        //Prevent ip .0 and .255 in List
                        if (Convert.ToInt32(IPLastPart(host.ToIpString())) > 0 && Convert.ToInt32(IPLastPart(host.ToIpString())) < 255)
                        {
                            IPAddress newIP   = IPAddress.Parse(host.ToIpString());
                            Host      newHost = new Host();
                            newHost.IP_Address   = newIP;
                            newHost.CountChecks  = 0;
                            newHost.RunningCheck = false;
                            ips.Add(newHost);
                        }
                    }
                }
            }
        }
示例#5
0
 private void tbIPStart_TextChanged(object sender, EventArgs e)
 {
     if (IpHelpers.isValidIP(tbIPStart.Text) == true) //Fill Network for LastIP
     {
         //Check if First end Last IP is in Subnet
         ipSeg = new IPSegment(tbIPStart.Text, tbSubnetMask.Text);
         if (cbUseSubnet.Checked == true)
         {
             if (CheckFirstIP() == true)
             {
                 btnStart.Enabled       = true;
                 tbIPEndNetwork.Enabled = true;
                 tbIPEnd.Enabled        = true;
             }
             else
             {
                 btnStart.Enabled       = false;
                 tbIPEndNetwork.Enabled = false;
                 tbIPEnd.Enabled        = false;
             }
         }
         else
         {
             if (cbUseSubnet.Enabled == true)
             {
                 tbIPEndNetwork.Text = IPFirstPart(tbIPStart.Text);
             }
             btnStart.Enabled = true;
         }
     }
     else
     {
         tbIPEndNetwork.Enabled = false;
         tbIPEnd.Enabled        = false;
         btnStart.Enabled       = false;
     }
 }