| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 
 |  
package testpackage;
import java.io.IOException;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.event.ResponseListener;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.Address;
import org.snmp4j.smi.GenericAddress;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;
 
 
public class test {
 
     String str2 ="";
     String res2 ="";
     String str3 ="";
     String res3 ="";
 
     public String tailleDisk() throws IOException 
 
{
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/161");
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
 
transport.listen();
 
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version1);
 
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,25,2,3,1,5,1})));//taille C:\
 
pdu.setType(PDU.GETNEXT);
 
ResponseListener listener = new ResponseListener()
{
public void onResponse(ResponseEvent event)
{
 
 
((Snmp)event.getSource()).cancel(event.getRequest(), this);
 
str2+=event.getResponse();
String mano = str2;
//System.out.println("La chaine traitee = " + mano);
 
int i = 0;
int ind1 = 0;
int ind2 = 0;
int lgreste = 0;
int nbrExtract = 0;
 
ind1 = mano.indexOf("VBS"); // mais est-ce que nous n'avons que VBS ? si non on corrige
// en ne prenant que la partie de reponse qui commence par le deuxieme ([)
ind1 = mano.lastIndexOf("["); // on trouve le deuxieme ([) celui de (VBS[) ou de (XXX[)
if (ind1 > -1) // si oui OK si non >>>>>> erreur de structure
{
mano = mano.substring(ind1); // on ne garde que la partie ou on veut extraire
//System.out.println("La zone d'extraction = " + mano + "\n");
ind1 = 0;
ind2 = 0;
 
//Extraction:
while (ind1 > -1)
{
ind1 = mano.indexOf(";");
if (ind1 > -1) // si oui OK
{
ind2 = mano.indexOf("= ");
if (ind2 > -1) // si oui OK, si non c'est une erreur de structure
{
nbrExtract++;
res2+=mano.substring(ind2+2, ind1) + "\n";
//System.out.println("resultat = " + resultat);
// on supprime la partie qui nous a servi a faire cette extraction
mano = mano.substring(ind1+1);
//System.out.println("mano = " + mano);
}
}
}
// il reste >>>> 1.3.6.1.2.1.1.5.0 = PCS]]
 
lgreste = mano.length();
// nous vérifions que mano termine bien par ]]
if (mano.endsWith("]]"))
{
ind2 = mano.indexOf("= ");
if (ind2 > -1) // si oui OK
{
nbrExtract++;
res2+= mano.substring(ind2+2, lgreste-2);
//System.out.println(resultat); //"resultat = " + resultat);
}
}
}
}
};
    snmp.send(pdu, target, null, listener);
 
   return res2;
    }
 
 
 
public String uniteAlloc() throws IOException 
 
{
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/161");
TransportMapping transport = new DefaultUdpTransportMapping();
Snmp snmp = new Snmp(transport);
 
transport.listen();
 
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version1);
 
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,25,2,3,1,4,1})));//unité allocation
 
pdu.setType(PDU.GET);
 
ResponseListener listener = new ResponseListener()
{
public void onResponse(ResponseEvent event)
{
 
 
((Snmp)event.getSource()).cancel(event.getRequest(), this);
 
str3+=event.getResponse();
String mano = str3;
//System.out.println("La chaine traitee = " + mano);
 
int i = 0;
int ind1 = 0;
int ind2 = 0;
int lgreste = 0;
int nbrExtract = 0;
 
ind1 = mano.indexOf("VBS"); // mais est-ce que nous n'avons que VBS ? si non on corrige
// en ne prenant que la partie de reponse qui commence par le deuxieme ([)
ind1 = mano.lastIndexOf("["); // on trouve le deuxieme ([) celui de (VBS[) ou de (XXX[)
if (ind1 > -1) // si oui OK si non >>>>>> erreur de structure
{
mano = mano.substring(ind1); // on ne garde que la partie ou on veut extraire
//System.out.println("La zone d'extraction = " + mano + "\n");
ind1 = 0;
ind2 = 0;
 
//Extraction:
while (ind1 > -1)
{
ind1 = mano.indexOf(";");
if (ind1 > -1) // si oui OK
{
ind2 = mano.indexOf("= ");
if (ind2 > -1) // si oui OK, si non c'est une erreur de structure
{
nbrExtract++;
res3+=mano.substring(ind2+2, ind1) + "\n";
//System.out.println("resultat = " + resultat);
// on supprime la partie qui nous a servi a faire cette extraction
mano = mano.substring(ind1+1);
//System.out.println("mano = " + mano);
}
}
}
// il reste >>>> 1.3.6.1.2.1.1.5.0 = PCS]]
 
lgreste = mano.length();
// nous vérifions que mano termine bien par ]]
if (mano.endsWith("]]"))
{
ind2 = mano.indexOf("= ");
if (ind2 > -1) // si oui OK
{
nbrExtract++;
res3+= mano.substring(ind2+2, lgreste-2);
//System.out.println(resultat); //"resultat = " + resultat);
}
}
}
}
};
    snmp.send(pdu, target, null, listener);  
   return res3;
    }  
 
 
} | 
Partager