1 2 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
|
public String fichierUntil(String device) throws IOException {
Connection conn = connexion.getconx();
StringBuffer sb = new StringBuffer();
char ch;
Service srv=new Service();
try {
readUntil1("show run int Fa0/0.3324");
while (true) {
do {
ch = (char) in.read();
sb.append(ch);
} while (!sb.toString().contains("description") && ch != '#' && !sb.toString().contains("%"));
if (sb.toString().contains("%")) {
System.out.print("Invalid Input");
sb = new StringBuffer();
} else if (sb.toString().contains("#")) {
in.close();
out.close();
return "";
} else if (sb.toString().contains("description")) {
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 10 && ch != 13);
/*Data 1*/
client = sb.toString();
srv.setdesc(client);
String chaine = sb.toString();
int pos = chaine.indexOf("_TM") + 3;
String number = chaine.substring(pos);
int next = number.indexOf("_");
if (next > -1) {
number = number.substring(0, next);
}
srv.setjr(number);
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (!sb.toString().contains("ip vrf forwarding") && !(sb.toString().contains("ip address ")) && !(sb.toString().contains("xconnect ")) && !(sb.toString().contains("#")));
if (sb.toString().contains("ip vrf forwarding")) {
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 10 && ch != 13);
/*Data2*/
vrf = sb.toString();
srv.setvrf(vrf);
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (!sb.toString().contains("ip address ") && !sb.toString().contains("#"));
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 32);
/*Data3 */
address = sb.toString();
srv.setaddress(address);
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 32);
//System.out.print(sb);
mask=sb.toString();
int pos1 = mask.lastIndexOf(".") + 1;
String lastPast_mask = mask.substring(pos1, mask.length());
lastPast_mask=lastPast_mask.trim();
int d = Integer.parseInt(lastPast_mask);
int pos_ip = address.lastIndexOf(".") + 1;
String lastPast_ip = address.substring(pos_ip, address.length());
lastPast_ip=lastPast_ip.trim();
int p = Integer.parseInt(lastPast_ip);
if(d==252){
p = p / 4;
p = p * 4;
}
else if(d==248)
{
p = p / 8;
p = p * 8;
}
String firstPart = address.substring(0, pos_ip);
String nouvelleAddress = firstPart + String.valueOf(p);
//System.out.println("Nouvelle address=" + nouvelleAddress);
srv.setaddress(nouvelleAddress);
} else if (sb.toString().contains("ip address ")) {
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 32 && ch != '#');
address = sb.toString();
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 32);
//System.out.print(sb);
mask=sb.toString();
address = address.trim();
mask = mask.trim();
int pos1 = mask.lastIndexOf(".") + 1;
String lastPast_mask = mask.substring(pos1, mask.length());
lastPast_mask=lastPast_mask.trim();
int d = Integer.parseInt(lastPast_mask);
int pos_ip = address.lastIndexOf(".") + 1;
String lastPast_ip = address.substring(pos_ip, address.length());
lastPast_ip=lastPast_ip.trim();
int p = Integer.parseInt(lastPast_ip);
if(d==252){
p = p / 4;
p = p * 4;
}
else if(d==248)
{
p= p / 8;
p = p * 8;
}
String firstPart = address.substring(0, pos_ip);
String nouvelleAddress = firstPart + String.valueOf(p);
srv.setaddress(nouvelleAddress);
sb = new StringBuffer();
} else if (sb.toString().contains("xconnect ")) {
sb = new StringBuffer();
do {
ch = (char) in.read();
sb.append(ch);
} while (ch != 32 && ch != '#');
address = sb.toString();
srv.setaddress(address);
sb = new StringBuffer();
}
}
alService.add(srv);
Statement stmt = conn.createStatement();
String query ="INSERT INTO ville1(client,JR,vrf,address) VALUES('"+getdesc()"+','"+getjr()+"')";
stmt.executeUpdate(query);
in.close();
out.close();
return "";
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public ArrayList<Service> getServiceList(){
return alService;
} |
Partager