コード例 #1
0
        //retourne le pourcentage d'encre présente dans x toner
        static public string getTonerStatus(string ipAdress, string printerName, int tonerNumber)
        {
            int    retries         = 1;
            int    TimeoutInMS     = 20000;
            int    tonerNumberDell = 0;
            string status;
            uint   currentlevel;
            uint   maxlevel;

            try
            {
                SNMP snmp = new SNMP();
                snmp.Open(ipAdress, "public", retries, TimeoutInMS);
                switch (tonerNumber)
                {
                case 1:
                    tonerNumberDell = 4;
                    break;

                case 2:
                    tonerNumberDell = 3;
                    break;

                case 3:
                    tonerNumberDell = 1;
                    break;

                case 4:
                    tonerNumberDell = 2;
                    break;
                }
                switch (printerName)
                {
                case "Dell 3010 cn":
                    currentlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.9.1." +
                                                  tonerNumberDell.ToString()));
                    maxlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.8.1." +
                                                  tonerNumberDell.ToString()));
                    break;

                default:
                    currentlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.9.1." +
                                                  tonerNumber.ToString()));
                    maxlevel =
                        Convert.ToUInt32(snmp.Get(".1.3.6.1.2.1.43.11.1.1.8.1." +
                                                  tonerNumber.ToString()));
                    break;
                }
                uint remaininglevel = (currentlevel * 100 / maxlevel);
                status = remaininglevel.ToString();
                snmp.Close();
            }
            catch (Exception)
            {
                status = "Informations non disponibles...";
            }
            return(status);
        }
コード例 #2
0
        // retourne le status du switch
        static public string getStatusSwitch(string ipAdress)
        {
            SNMP   snmp;
            int    DeviceId = 1;
            int    retries = 1;
            int    TimeoutInMS = 20000;
            string Result1Str; string status = "";

            try
            {
                string[] ErrorMessageText = new string[8];
                ErrorMessageText[0] = "service recquis";
                ErrorMessageText[1] = "Eteinte";
                ErrorMessageText[2] = "Bourrage papier";
                ErrorMessageText[3] = "porte ouverte";
                ErrorMessageText[4] = "pas de toner";
                ErrorMessageText[5] = "niveau toner bas";
                ErrorMessageText[6] = "plus de papier";
                ErrorMessageText[7] = "niveau de papier bas";

                snmp = new SNMP();
                snmp.Open(ipAdress, "public", retries, TimeoutInMS);//.1.3.6.1.2.1.2.2.1.7.25
                uint nbPort = snmp.GetAsByte(String.Format(".1.3.6.1.2.1.2.1.0"));
                snmp.Close();
                System.Console.WriteLine("nombre de port : " + nbPort);

                for (int i = 1; i <= nbPort; i++)
                {
                    snmp = new SNMP();
                    snmp.Open(ipAdress, "public", retries, TimeoutInMS);//.1.3.6.1.2.1.2.2.1.7.25//.1.3.6.1.2.1.2.1.0//.1.3.6.1.2.1.2.2.1.6.
                    string adressResult = snmp.Get(".1.3.6.1.2.1.2.2.1.6." + i);
                    byte[] ba           = Encoding.Default.GetBytes(adressResult);
                    string hexString    = BitConverter.ToString(ba);
                    uint   statusResult = snmp.GetAsByte(".1.3.6.1.2.1.2.2.1.8." + i);

                    switch (statusResult)
                    {
                    case 1:
                        Result1Str = "up";
                        break;

                    case 2:
                        Result1Str = "down";
                        break;

                    case 3:
                        Result1Str = "testing";
                        break;

                    case 4:
                        Result1Str = "unknown";
                        break;

                    case 5:
                        Result1Str = "dormant";
                        break;

                    case 6:
                        Result1Str = "notPresent";
                        break;

                    case 7:
                        Result1Str = "lowerLayerDown";
                        break;

                    default:
                        Result1Str = "code inconnu" + statusResult;
                        break;
                    }
                    Console.WriteLine("  port " + i + " adresse : " + hexString + " " + statusResult + " " + Result1Str);
                    snmp.Close();
                }
            }
            catch (Exception)
            {
                status = "Informations non disponibles...";
            }
            return(status);
        }
コード例 #3
0
        // retourne le status de l'imprimante
        static public string getStatus(string ipAdress)
        {
            SNMP   snmp;
            int    DeviceId = 1;
            int    retries = 1;
            int    TimeoutInMS = 20000;
            string Result1Str; string status;

            try
            {
                string[] ErrorMessageText = new string[8];
                ErrorMessageText[0] = "service recquis";
                ErrorMessageText[1] = "Eteinte";
                ErrorMessageText[2] = "Bourrage papier";
                ErrorMessageText[3] = "porte ouverte";
                ErrorMessageText[4] = "pas de toner";
                ErrorMessageText[5] = "niveau toner bas";
                ErrorMessageText[6] = "plus de papier";
                ErrorMessageText[7] = "niveau de papier bas";

                snmp = new SNMP();
                snmp.Open(ipAdress, "public", retries, TimeoutInMS);
                uint WarningErrorBits = snmp.GetAsByte(String.Format("25.3.5.1.2.{0}",
                                                                     DeviceId));
                uint statusResult = snmp.GetAsByte(String.Format("25.3.2.1.5.{0}",
                                                                 DeviceId));

                switch (statusResult)
                {
                case 2:
                    Result1Str = "OK";
                    break;

                case 3:
                    Result1Str = "Avertissement: ";
                    break;

                case 4:
                    Result1Str = "Test: ";
                    break;

                case 5:
                    Result1Str = "Hors de fonctionnement: ";
                    break;

                default:
                    Result1Str = "Code Inconnu: " + statusResult;
                    break;
                }
                string Str = "";

                if ((statusResult == 3 || statusResult == 5))
                {
                    int Mask   = 1;
                    int NumMsg = 0;
                    for (int i = 0; i < 8; i++)
                    {
                        if ((WarningErrorBits & Mask) == Mask)
                        {
                            if (Str.Length > 0)
                            {
                                Str += ", ";
                            }
                            Str   += ErrorMessageText[i];
                            NumMsg = NumMsg + 1;
                        }
                        Mask = Mask * 2;
                    }
                }
                status = Result1Str + Str;
                snmp.Close();
            }
            catch (Exception)
            {
                status = "Informations non disponibles...";
            }
            return(status);
        }