Beispiel #1
0
        /// <summary>
        /// Retrieves the data of all MPS Systems marked for gathereing information
        /// </summary>
        /// <returns></returns>
        public List <OidData> GainData()
        {
            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "RetrieveDeviceInformation", "GainData");
            var dt = Config.GetInstance().Query("select * from Devices where active='1' or active='True'");
            // DataTable resultTable = null;
            var data = new List <OidData>();

            for (var i = 0; i < dt.Rows.Count; i++)
            {
                if (DeviceTools.IdentDevice(dt.Rows[i].Field <string>("Ip")).Length > 0)
                {
                    if (FnPing.PingAndCheckSuccess(IPAddress.Parse(dt.Rows[i].Field <string>("Ip"))))
                    {
                        if (SnmpClient.ReadDeviceOiDs(dt.Rows[i].Field <string>("Ip"),
                                                      DeviceTools.IdentDevice(dt.Rows[i].Field <string>("Ip")), out OidData oidData))
                        {
                            if (oidData != null)
                            {
                                data.Add(oidData);
                            }
                        }
                    }
                }
            }

            return(data);
        }
Beispiel #2
0
        /// <summary>
        /// Inserts the in devices via thread.
        /// </summary>
        /// <param name="param">The parameter.</param>
        private void InsertInDevicesViaThread(object param)
        {
            var obj       = (object[])param;
            var ipAddress = (string)obj[0];
            var aktiv     = (string)obj[1];

            try
            {
                var ident  = DeviceTools.IdentDevice(ipAddress);
                var modell = "";
                var serial = "";
                var asset  = "";
                FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "EditDevices",
                                                 "InsertDevicesViaThread " + ipAddress);

                var ip = IPAddress.Parse(ipAddress);
                ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(adjustProgress));

                if (ident.Length > 0)
                {
                    var dt = Config.GetInstance().GetOidRowByPrivateId(ident);
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    modell = SnmpClient.GetOidValue(ipAddress, dt.Rows[0].Field <string>("Model"));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    serial = SnmpClient.GetOidValue(ipAddress, dt.Rows[0].Field <string>("SerialNumber"));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    asset = SnmpClient.GetOidValue(ipAddress, dt.Rows[0].Field <string>("AssetNumber"));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                }
                else
                {
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                    ProgressBarProgress.Dispatcher.BeginInvoke(DispatcherPriority.Background,
                                                               new Action(adjustProgress));
                }

                Config.GetInstance().InsertInDeviceTable(
                    aktiv,
                    ip.GetAddressBytes(),
                    modell,
                    serial,
                    asset
                    );
            }
            catch (SnmpIdentNotFoundException)
            {
            }

            DataGridDevices.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(LoadGridData));
        }
Beispiel #3
0
        public void TestDiscovery()
        {
            var data = SnmpClient.Discover();

            Assert.IsNotNull(data);

            // TODO: we can't access snmp devices, how to test?
        }
    public static void ReadCallback(IAsyncResult ar)
    {
        String content = String.Empty;

        // Retrieve the state object and the handler socket
        // from the asynchronous state object.
        StateObject state   = (StateObject)ar.AsyncState;
        Socket      handler = state.workSocket;

        // Read data from the client socket.
        int bytesRead = handler.EndReceive(ar);

        if (bytesRead > 0)
        {
            // There  might be more data, so store the data received so far.
            state.sb.Append(Encoding.ASCII.GetString(
                                state.buffer, 0, bytesRead));

            // Check for end-of-file tag. If it is not there, read
            // more data.
            content = state.sb.ToString();
            if (content.IndexOf("\n") > -1)
            {
                // All the data has been read from the
                // client. Display it on the console.
                Console.WriteLine("Read {0} bytes from socket. \n Data : {1}",
                                  content.Length, content);
                // Echo the data back to the client.
                if (content.Equals("hi"))
                {
                    Send(handler, "hi android");
                }
                else
                {
                    Send(handler, SnmpClient.getRequestProxy(content));
                }

                state.sb.Length = 0;

                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                     new AsyncCallback(ReadCallback), state);
            }
            else
            {
                // Not all data received. Get more.
                handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                                     new AsyncCallback(ReadCallback), state);
            }
        }
    }
    public AsynchronousSocketListener()
    {
        // Data buffer for incoming data.
        byte[] bytes = new Byte[1024];

        IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Parse(SnmpClient.GetLocalIPAddress()), 1235);

        // Create a TCP/IP socket.
        Socket listener = new Socket(AddressFamily.InterNetwork,
                                     SocketType.Stream, ProtocolType.Tcp);

        // Bind the socket to the local endpoint and listen for incoming connections.
        try
        {
            listener.Bind(localEndPoint);
            listener.Listen(100);

            while (true)
            {
                // Set the event to nonsignaled state.
                allDone.Reset();

                // Start an asynchronous socket to listen for connections.
                Console.WriteLine(IPAddress.Parse(SnmpClient.GetLocalIPAddress()));
                Console.WriteLine("Waiting for a connection...");
                listener.BeginAccept(
                    new AsyncCallback(AcceptCallback),
                    listener);

                // Wait until a connection is made before continuing.
                allDone.WaitOne();
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }

        Console.WriteLine("\nPress ENTER to continue...");
        Console.Read();
    }
Beispiel #6
0
        public void ListenTest()
        {
            SnmpClient snmpClient = new SnmpClient();

            snmpClient.Listen();
        }
Beispiel #7
0
        public void GetTableTest()
        {
            SnmpClient snmpClient = new SnmpClient();

            ShowGetTableResult(snmpClient.GetTable("1.3.6.1.2.1.6.13"));
        }
Beispiel #8
0
        public void GetRequestTest()
        {
            SnmpClient snmpClient = new SnmpClient();

            Assert.IsNotNull(snmpClient.GetRequest("1.3.6.1.2.1.1.3.0"));
        }
        /// <summary>
        /// Searches for printer.
        /// </summary>
        /// <param name="state">The state.</param>
        private void SearchForPrinter(object state)
        {
            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices", "SearchForPrinter");

            var fp = new FnPing(StartIpAddress, EndIpAddress);

            var pingResultsIps = fp.RangePing();

            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices",
                                             "SearchForPrinter - pingResultsIps Success Count:" + pingResultsIps.SuccessIpAddresses.Count);

            foreach (var ipAddress in pingResultsIps.SuccessIpAddresses)
            {
                try
                {
                    var ident  = DeviceTools.IdentDevice(ipAddress.ToString());
                    var modell = "";
                    var serial = "";
                    var asset  = "";
                    if (ident.Length > 0)
                    {
                        if (Config.GetInstance().Query(
                                "Select * from Devices where IP='" + ipAddress.ToString() + "';").Rows.Count >
                            0)
                        {
                            var dts = Config.GetInstance().GetOidRowByPrivateId(ident);
                            modell = SnmpClient.GetOidValue(ipAddress.ToString(), dts.Rows[0].Field <string>("Model"));
                            serial = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                            dts.Rows[0].Field <string>("SerialNumber"));
                            asset = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                           dts.Rows[0].Field <string>("AssetNumber"));
                            Config.GetInstance().UpdateDeviceTable(
                                "1",
                                ipAddress.GetAddressBytes(),
                                modell,
                                serial,
                                asset,
                                ipAddress.GetAddressBytes()
                                );
                            FnLog.GetInstance().AddToLogList(FnLog.LogType.MinorRuntimeInfo, "SearchForDevices",
                                                             "SearchForPrinter Found: " + ipAddress.ToString() + " Type: " + ident);
                        }
                        else
                        {
                            var dts = Config.GetInstance().GetOidRowByPrivateId(ident);

                            if (dts.Rows.Count > 0)
                            {
                                modell = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                                dts.Rows[0].Field <string>("Model"));
                                serial = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                                dts.Rows[0].Field <string>("SerialNumber"));
                                asset = SnmpClient.GetOidValue(ipAddress.ToString(),
                                                               dts.Rows[0].Field <string>("AssetNumber"));
                                Config.GetInstance().Query("Delete from Devices where IP = '" +
                                                           ipAddress.ToString() + "'; ");
                                Config.GetInstance().InsertInDeviceTable(
                                    "1",
                                    ipAddress.GetAddressBytes(),
                                    modell,
                                    serial,
                                    asset
                                    );
                            }
                        }
                    }
                }
                catch (SnmpIdentNotFoundException)
                {
                }
            }
            DataGridDevices.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(LoadGridData));
            ButtonSearch.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(ShowStartButton));
        }