Beispiel #1
0
        public List <HostModel> ScanSubnet(string subnet, int timeout)
        {
            Ping      myPing;
            PingReply reply;
            IPAddress address;

            byte[] macAddr = new byte[6];

            IPHostEntry host;

            List <HostModel> retModelList = new List <HostModel>();

            for (int i = 1; i < 255; i++)
            {
                HostModel model = new HostModel();

                string subnetn = "." + i.ToString();

                myPing = new Ping();
                reply  = myPing.Send(subnet + subnetn, timeout);

                if (reply.Status == IPStatus.Success)
                {
                    try
                    {
                        address = IPAddress.Parse(subnet + subnetn);
                        host    = Dns.GetHostEntry(address);

                        model.IP_ADDRESS = subnet + subnetn;
                        model.HOSTNAME   = host.HostName;
                        model.STATUS     = "Up";

                        SendARP((int)BitConverter.ToInt32(address.GetAddressBytes(), 0), 0, macAddr, ref macAddrLen);
                        if (MacAddresstoString(macAddr) != "00-00-00-00-00-00")
                        {
                            string macString = MacAddresstoString(macAddr);
                            model.MAC_ADDRESS = macString;
                            model.INTERFACE   = GetDeviceInfoFromMac(macString);
                        }
                    }
                    catch (Exception)
                    {
                    }

                    retModelList.Add(model);
                }
            }

            return(retModelList);
        }
Beispiel #2
0
        public HostModel ScanIP(string ipString, int timeout)
        {
            HostModel retModel = new HostModel();

            Ping      myPing;
            PingReply reply;
            IPAddress address;

            byte[] macAddr = new byte[6];

            IPHostEntry host;

            myPing = new Ping();
            reply  = myPing.Send(ipString, timeout);

            if (reply.Status == IPStatus.Success)
            {
                try
                {
                    address = IPAddress.Parse(ipString);
                    host    = Dns.GetHostEntry(address);

                    retModel.IP_ADDRESS = ipString;
                    retModel.HOSTNAME   = host.HostName;
                    retModel.STATUS     = "Up";

                    SendARP((int)BitConverter.ToInt32(address.GetAddressBytes(), 0), 0, macAddr, ref macAddrLen);
                    if (MacAddresstoString(macAddr) != "00-00-00-00-00-00")
                    {
                        string macString = MacAddresstoString(macAddr);
                        retModel.MAC_ADDRESS = macString;
                        retModel.INTERFACE   = GetDeviceInfoFromMac(macString);
                    }
                }
                catch (Exception)
                {
                }

                return(retModel);
            }

            retModel = null;
            return(retModel);
        }