diff --git a/api/src/routes/ipv4.py b/api/src/routes/ipv4.py index a23d589..dfa9faf 100644 --- a/api/src/routes/ipv4.py +++ b/api/src/routes/ipv4.py @@ -102,4 +102,4 @@ async def get_mask(ipv4: str) -> dict: async def get_vlsm(baseip: str, subnet: str) -> dict: """Implement the VLSM (Variable Length Subnet Mask) technique.""" res = vlsm(baseip, subnet) - return {"ipv4": res} + return {"subnet": res} diff --git a/front-js/src/app/modules/vlsm/Cours.tsx b/front-js/src/app/modules/vlsm/Cours.tsx new file mode 100644 index 0000000..a7818f6 --- /dev/null +++ b/front-js/src/app/modules/vlsm/Cours.tsx @@ -0,0 +1,124 @@ +import Title from "@/components/Title"; +import Text from "@/components/Text"; +import React from "react"; +import Space from "@/components/Space"; +import { Emoji, EmojiProvider } from "react-apple-emojis"; +import emojiData from "react-apple-emojis/src/data.json"; +import { Alert, CircularProgress } from "@mui/material"; +import axios from "@/axiosConfig"; +import Cookies from "js-cookie"; +import { Code, solarizedLight } from "react-code-blocks"; +import Box from "@/components/Box"; +import Button from "@/components/Button"; +import Input from "@/components/Input"; +import { AxiosError } from "axios"; + +const Cours: React.FC = () => { + const [addrRestante, setAddrRestante] = React.useState(""); + const [res, setRes] = React.useState(""); + const [isLoading, setIsLoading] = React.useState(false); + + const handleAddrRestante = async (e: { preventDefault: () => void }) => { + setIsLoading(true); + setRes(""); + e.preventDefault(); + try { + const response = await axios.get("/ipv4/vlsm/192.168.1.0/15,30,50", { + headers: { + Authorization: `Bearer ${Cookies.get("access_token")}`, + }, + }); + const data = response.data; + if (response.status === 200) { + let lastRange = data.subnet[data.subnet.length - 1].range; + lastRange = lastRange.split(" - ")[1]; + const listLastRange = lastRange.split("."); + const newLastDigit = + parseInt(listLastRange[listLastRange.length - 1]) + 1; + listLastRange.pop(); + listLastRange.push(newLastDigit.toString()); + const ok = listLastRange.join(".") + " - 192.168.1.254"; + if (addrRestante == ok) { + setRes("Bravo !"); + } else { + setRes("Mauvaise réponse !"); + } + } + } catch (error: unknown) { + const axiosError = error as AxiosError; + if (axiosError.response?.status === 400) { + setRes("Erreur interne"); + } else { + setRes("Erreur interne"); + } + } + setIsLoading(false); + }; + + return ( + <> + + + Introduction + + VLSM (Variable Length Subnet Masking) est une technique de + sous-réseautage qui permet de créer des sous-réseaux de différentes + tailles. Cette technique est utilisée pour optimiser + l’utilisation des adresses IP. + + + Fonctionnement VLSM + + + VLSM permet de diviser un réseau en sous-réseaux de différentes + tailles. Chaque sous-réseau peut accueillir un nombre minimisé de + machine. Cela permet d’optimiser l’utilisation des + adresses IP. + + + Attention il ne faut pas oublier de réserver une adresse pour le + réseau et une pour le broadcast. + + + Essayez ! <Emoji name="test-tube" width={32} /> + + + Notre réseau{" "} + {" "} + contient des sous-réseaux avec 15 machines, 30 machines et 50 + machines. Qu’elle est la plage d’adresses IP restante ? + +
+ setAddrRestante(e.target.value)} + value={addrRestante} + type="text" + placeholder="192.168.1.xxx - 192.168.1.xxx" + margin={{ bottom: "20px" }} + required + label="Plage restante" + /> +