Ejemplo n.º 1
0
 public static void Add(NetworkDevice fp)
 {
     if (List.Count(p => Equals(p.IPAddress, fp.IPAddress) && p.Port == fp.Port) == 0)
     {
         List.Add(fp);
     }
 }
Ejemplo n.º 2
0
 // Constructor
 public DeviceFoundEventArgs(NetworkDevice device)
 {
     Device = device;
 }
Ejemplo n.º 3
0
        private void PortScanner(IEnumerable<int> ports, IPAddress ipaddress, ManualResetEvent mre)
        {
            string hostname = "Unknown";
            try
            {
                var ipToDomainName = Dns.GetHostEntry(ipaddress);
                hostname = ipToDomainName.HostName;
            }
            catch
            {
            }

            foreach (int iport in ports)
            {
                try
                {
                    string req = ipaddress + ":" + iport;
                    var request = (HttpWebRequest)WebRequest.Create("http://" + req);
                    request.Referer = "";
                    request.Timeout = 3000;
                    request.UserAgent = "Mozilla/5.0";
                    request.AllowAutoRedirect = false;
                    request.KeepAlive = false;

                    HttpWebResponse response = null;

                    try
                    {
                        response = (HttpWebResponse)request.GetResponse();
                    }
                    catch (WebException e)
                    {
                        response = (HttpWebResponse)e.Response;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogMessageToFile("Web error from " + ipaddress + ":" + iport + " " + ex.Message, "NetworkDiscovery");
                    }
                    if (response != null)
                    {
                        Logger.LogMessageToFile("Web response from " + ipaddress + ":" + iport + " " +
                                                    response.StatusCode, "NetworkDiscovery");
                        if (response.Headers != null)
                        {
                            string webserver = "yes";
                            foreach (string k in response.Headers.AllKeys)
                            {
                                if (k.ToLower().Trim() == "server")
                                    webserver = response.Headers[k];
                            }
                            int iport1 = iport;
                            if (DeviceFound != null)
                            {
                                var nd = new NetworkDevice(ipaddress, iport1, hostname, webserver);
                                DeviceFound(this, new DeviceFoundEventArgs(nd));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogMessageToFile("Web error from " + ipaddress + ":" + iport + " " + ex.Message, "NetworkDiscovery");

                }
            }
            mre.Set();
        }
Ejemplo n.º 4
0
 public static void Add(NetworkDevice fp)
 {
     if (List.Count(p => Equals(p.IPAddress, fp.IPAddress) && p.Port == fp.Port) == 0)
         List.Add(fp);
 }
Ejemplo n.º 5
0
 // Constructor
 public DeviceFoundEventArgs(NetworkDevice device) => Device = device;
Ejemplo n.º 6
0
        private void PortScanner(IEnumerable <int> ports, IPAddress ipaddress, ManualResetEvent mre)
        {
            string hostname = "Unknown";

            try
            {
                var ipToDomainName = Dns.GetHostEntry(ipaddress);
                hostname = ipToDomainName.HostName;
            }
            catch
            {
            }

            foreach (int iport in ports)
            {
                try
                {
                    string req     = ipaddress + ":" + iport;
                    var    request = (HttpWebRequest)WebRequest.Create("http://" + req);
                    request.Referer           = "";
                    request.Timeout           = 3000;
                    request.UserAgent         = "Mozilla/5.0";
                    request.AllowAutoRedirect = false;
                    request.KeepAlive         = false;

                    HttpWebResponse response = null;

                    try
                    {
                        response = (HttpWebResponse)request.GetResponse();
                    }
                    catch (WebException e)
                    {
                        response = (HttpWebResponse)e.Response;
                    }
                    catch (Exception ex)
                    {
                        Logger.LogMessage("Web error from " + ipaddress + ":" + iport + " " + ex.Message, "NetworkDiscovery");
                    }
                    if (response != null)
                    {
                        Logger.LogMessage("Web response from " + ipaddress + ":" + iport + " " +
                                          response.StatusCode, "NetworkDiscovery");
                        if (response.Headers != null)
                        {
                            string webserver = "yes";
                            foreach (string k in response.Headers.AllKeys)
                            {
                                if (k.ToLower().Trim() == "server")
                                {
                                    webserver = response.Headers[k];
                                }
                            }
                            int iport1 = iport;
                            if (DeviceFound != null)
                            {
                                var nd = new NetworkDevice(ipaddress, iport1, hostname, webserver);
                                DeviceFound(this, new DeviceFoundEventArgs(nd));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogMessage("Web error from " + ipaddress + ":" + iport + " " + ex.Message, "NetworkDiscovery");
                }
            }
            mre.Set();
        }