diff --git a/front-js/src/app/dashboard/page.tsx b/front-js/src/app/dashboard/page.tsx index 63f403b..16f8868 100644 --- a/front-js/src/app/dashboard/page.tsx +++ b/front-js/src/app/dashboard/page.tsx @@ -157,9 +157,10 @@ export default function Dashboard() { router.push("/modules/tcp")} /> diff --git a/front-js/src/app/modules/tcp/Cours.tsx b/front-js/src/app/modules/tcp/Cours.tsx new file mode 100644 index 0000000..7eb464d --- /dev/null +++ b/front-js/src/app/modules/tcp/Cours.tsx @@ -0,0 +1,49 @@ +import Title from "@/components/Title"; +import Text from "@/components/Text"; +import React from "react"; +import Space from "@/components/Space"; +import Box from "@/components/Box"; + +const Cours: React.FC = () => { + return ( + <> + + Introduction + + TCP (Transmission Control Protocol) est un protocole de communication + qui assure la transmission de données entre deux machines. Il garantit + que les données envoyées par une machine arrivent bien à l’autre + machine, dans le bon ordre et sans erreur. + + + Fonctionnement TCP + + + TCP fonctionne en établissant une connexion entre deux machines avant + de transmettre des données. Cette connexion est appelée{" "} + connexion TCP. Elle est établie en trois étapes : + +
    +
  1. + Établissement de la connexion : Les deux machines + s’échangent des paquets pour s’assurer + qu’elles sont prêtes à communiquer. +
  2. +
  3. + Transfert des données : Les données sont envoyées en + plusieurs paquets, chacun étant numéroté pour être reconstitué + dans le bon ordre. +
  4. +
  5. + Fin de la connexion : Les deux machines s’échangent + des paquets pour clôturer la connexion. +
  6. +
+
+
+
+ + ); +}; + +export default Cours; diff --git a/front-js/src/app/modules/tcp/TcpSandbox.tsx b/front-js/src/app/modules/tcp/TcpSandbox.tsx new file mode 100644 index 0000000..e9d346d --- /dev/null +++ b/front-js/src/app/modules/tcp/TcpSandbox.tsx @@ -0,0 +1,171 @@ +import Title from "@/components/Title"; +import Button from "@/components/Button"; +import Input from "@/components/Input"; +import Space from "@/components/Space"; +import React from "react"; +import { useState } from "react"; +import axios from "@/axiosConfig"; +import Cookies from "js-cookie"; +import { AxiosError } from "axios"; +import { Alert, CircularProgress } from "@mui/material"; +import Box from "@/components/Box"; + +const TcpSandbox: React.FC = () => { + const [res, setRes] = useState(""); + const [ping, setPing] = useState<{ + rtt_ms: number; + packet_size: number; + ttl: number; + source: string; + destination: string; + } | null>(null); + const [command, setCommand] = useState(""); + const [error, setError] = useState(""); + const [isLoading, setIsLoading] = useState(false); + + const handlePing = async (e: { preventDefault: () => void }) => { + setIsLoading(true); + e.preventDefault(); + const parts = command.split(" "); + if (parts.length < 2 || parts.length > 2) { + setError("Commande invalide"); + setRes(""); + setIsLoading(false); + return; + } + if (parts[0] !== "ping") { + setError("Commande invalide"); + setRes(""); + setIsLoading(false); + return; + } + try { + const ip_port = parts[1].split(":"); + if (ip_port.length < 2 || ip_port.length > 2) { + setError("Commande invalide"); + setRes(""); + setIsLoading(false); + return; + } + const ip = ip_port[0]; + const port = ip_port[1]; + + const response = await axios.get("/scapy/tcp-test/" + ip + "/" + port, { + headers: { + Authorization: `Bearer ${Cookies.get("access_token")}`, + }, + }); + const data = response.data; + if (response.status === 200) { + setRes(data.message); + const formattedPing = { + rtt_ms: data.details.rtt_ms, + packet_size: data.details.packet_size, + ttl: data.details.ttl, + source: data.details.source, + destination: data.details.destination, + }; + setPing(formattedPing); + setError(""); + } + } catch (error: unknown) { + const axiosError = error as AxiosError; + if (axiosError.response?.status === 404) { + setRes(""); + setError("Impossible de résoudre l'adresse"); + } else { + setError("Erreur lors du ping TCP"); + setRes(""); + } + } + setIsLoading(false); + }; + + return ( + <> + +
+ Ping TCP + + setCommand(e.target.value)} + required + label="Commande ping" + /> +