Refonte du repo

This commit is contained in:
JunkJumper
2020-05-20 17:01:49 +02:00
parent 4962efbd17
commit 45f4d2dffe
165 changed files with 83943 additions and 84353 deletions

65
src/TD7/ip/IP.java Normal file
View File

@ -0,0 +1,65 @@
package ip;
public class IP {
private String ip;
public IP(String s) {
if (ipValide(s))
ip = s;
}
public String getIP() {
return ip;
}
public IP getPasserelle(IP masque) {
String ipPass = "";
switch (masque.ip) {
case "255.0.0.0" :
ipPass = this.ip.substring(0, this.ip.indexOf(".")+1)+"255.255.255";
break;
case "255.255.0.0" :
ipPass = this.ip.substring(0, this.ip.indexOf(".")+1);
String temp = ip.substring(ip.indexOf(".")+1);
ipPass += temp.substring(0, temp.indexOf(".")+1)+"255.255";
break;
case "255.255.255.0" :
ipPass = this.ip.substring(0, ip.lastIndexOf(".")+1)+"255";
break;
}
return new IP(ipPass);
}
public String toString() {
return ip;
}
public static boolean ipValide(String ip) {
if (ip.substring(0, 1).equals(".") || ip.substring(ip.length()-1).equals(".")) {
System.out.println("Bad first or last character");
return false;
}
String[] ipSep = ip.split("\\.");
if (ipSep.length != 4) {
System.out.println("Bad ip length "+ipSep.length);
return false;
}
for (String s : ipSep) {
if (s.length() == 0) {
System.out.println("Empty ip field");
return false;
}
int num = Integer.parseInt(s);
if ((num<0) || (num>255)) {
System.out.println("Bad ip field");
return false;
}
}
return true;
}
}

47
src/TD7/ip/MainIp.java Normal file
View File

@ -0,0 +1,47 @@
package ip;
public class MainIp {
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] tabIp = new String[10];
boolean[] tabRetatt = new boolean[tabIp.length];
boolean[] tabRetour = new boolean[tabIp.length];
tabIp[0] = "";
tabIp[1] = "127.0.0.1";
tabIp[2] = "127.231.1.1";
tabIp[3] = "1.2.3.4";
tabIp[4] = "12.2.3";
tabIp[5] = "12.3.213.123.123";
tabIp[6] = "1231.12.2.3";
tabIp[7] = ".1.2.3";
tabIp[8] = "1.2.3.";
tabIp[9] = "1.2..3";
tabRetatt[0] = false;
tabRetatt[1] = true;
tabRetatt[2] = true;
tabRetatt[3] = true;
tabRetatt[4] = false;
tabRetatt[5] = false;
tabRetatt[6] = false;
tabRetatt[7] = false;
tabRetatt[8] = false;
tabRetatt[9] = false;
for (int i = 0; i < tabRetatt.length; i++) {
tabRetour[i] = IP.ipValide(tabIp[i]);
}
System.out.println("attendu - retourne :");
for (int i = 0; i < tabRetatt.length; i++) {
System.out.println(tabRetatt[i] + " - " + tabRetour[0]);
}
}
}