Пример #1
0
        static void GetManufacturers()
        {
            string manufacturer = "";

            foreach (var item in AllInfo)
            {
                if (item.macAddress != null)
                {
                    manufacturer = (MacAPI.GetMAC(item.macAddress)).result.company;
                }
                InfoToSend s = AllInfo.Find(x => x.ipAddress == item.ipAddress);
                s.manf = manufacturer;
            }
        }
Пример #2
0
        static void pingDone(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;

            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                if (resolveNames)
                {
                    string name = null;
                    try
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                        name = hostEntry.HostName;
                    }
                    catch (SocketException ex)
                    {
                        name = ip;
                    }
                    string opers = "";
                    if (e.Reply.Options.Ttl == 64)
                    {
                        opers = "Linux/Unix/Android";
                    }
                    else if (e.Reply.Options.Ttl == 128)
                    {
                        opers = "Windows";
                    }
                    else
                    {
                        opers = "Solaris/AIX";
                    }
                    InfoToSend s = AllInfo.Find(x => x.ipAddress == ip);
                    s.displayName = name;
                    s.os          = opers;
                }
                lock (lockObj)
                {
                    upCount++;
                }
            }
            else
            {
                InfoToSend s = AllInfo.Find(x => x.ipAddress == ip);
                s.displayName = ip;
                s.os          = "(No Reply)";
            }
            countdown.Signal();
        }
Пример #3
0
 static void startScan(string ip)
 {
     countdown = new CountdownEvent(1);
     new Thread(delegate()
     {
         try
         {
             Ping p           = new Ping();
             p.PingCompleted += new PingCompletedEventHandler(pingDone);
             p.SendAsync(ip, 100, ip);
         }
         catch (SocketException ex)
         {
             InfoToSend s  = AllInfo.Find(x => x.ipAddress == ip);
             s.displayName = ip;
         }
     }).Start();
     countdown.Wait();
 }
Пример #4
0
        static void pingDone2(object sender, PingCompletedEventArgs e)
        {
            string ip = (string)e.UserState;

            //Functions.log(string.Format("{0}", e.Reply.Options.Ttl.ToString()), 2);
            if (e.Reply != null && e.Reply.Status == IPStatus.Success)
            {
                if (resolveNames)
                {
                    string name = null;
                    string ips  = null;
                    try
                    {
                        IPHostEntry hostEntry = Dns.GetHostEntry(ip);
                        name = hostEntry.HostName;
                        ips  = getMacByIp(ip);
                    }
                    catch (SocketException ex)
                    {
                        name = ip;
                    }

                    //  Functions.log(string.Format("{0} ({1}) is up: ({2} ms) MacAddress is: {3}, TTL is: {4}", ip, name, e.Reply.RoundtripTime, ips, e.Reply.Options.Ttl), 2);
                    string opers = "";
                    if (e.Reply.Options.Ttl == 64)
                    {
                        opers = "Linux/Unix/Android";
                    }
                    else if (e.Reply.Options.Ttl == 128)
                    {
                        opers = "Windows";
                    }
                    else
                    {
                        opers = "Solaris/AIX";
                    }
                    string manufacturer = "";
                    //if(ips != null )
                    //{
                    //    manufacturer = (MacAPI.GetMAC(ips)).result.company;
                    //}
                    InfoToSend s = AllInfo.Find(x => x.ipAddress == ip);
                    if (s == null)
                    {
                        AllInfo.Add(new InfoToSend()
                        {
                            displayName = name,
                            macAddress  = ips,
                            ipAddress   = ip,
                            os          = opers,
                            manf        = manufacturer
                        });
                    }
                    else
                    {
                        s.displayName = name;
                        s.os          = opers;
                    }
                }
                else
                { //but it's reachable doe.
                  // Functions.log(string.Format("{0} is up: ({1} ms)", ip, e.Reply.RoundtripTime), 2);
                }
                lock (lockObj)
                {
                    upCount++;
                }
            }
            else if (e.Reply == null)
            {
                //Functions.log(string.Format("Pinging {0} failed. (Null Reply object?)", ip), 3);
            }
            countdown.Signal();
        }