diff --git a/scan_ip.py b/scan_ip.py index 46ee3ed..5562bda 100644 --- a/scan_ip.py +++ b/scan_ip.py @@ -8,7 +8,7 @@ def check_port(ip, port): try: # Créer une connexion à l'IP et au port spécifié with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: - s.settimeout(0.03) # Timeout après 1 seconde + s.settimeout(0.30) # Timeout après 1 seconde result = s.connect_ex((str(ip), port)) # connect_ex retourne 0 si connecté return result == 0 # Si la connexion est réussie, le port est ouvert except socket.error: diff --git a/tests/__pycache__/test_example.cpython-311-pytest-7.3.1.pyc b/tests/__pycache__/test_example.cpython-311-pytest-7.3.1.pyc new file mode 100644 index 0000000..ce0700e Binary files /dev/null and b/tests/__pycache__/test_example.cpython-311-pytest-7.3.1.pyc differ diff --git a/tests/__pycache__/test_scan_ip.cpython-311-pytest-7.3.1.pyc b/tests/__pycache__/test_scan_ip.cpython-311-pytest-7.3.1.pyc new file mode 100644 index 0000000..1369976 Binary files /dev/null and b/tests/__pycache__/test_scan_ip.cpython-311-pytest-7.3.1.pyc differ diff --git a/tests/ceciestuntest b/tests/ceciestuntest deleted file mode 100644 index fd40910..0000000 --- a/tests/ceciestuntest +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/tests/test_example.py b/tests/test_example.py.old similarity index 100% rename from tests/test_example.py rename to tests/test_example.py.old diff --git a/tests/test_scan_ip.py b/tests/test_scan_ip.py new file mode 100644 index 0000000..3262fd1 --- /dev/null +++ b/tests/test_scan_ip.py @@ -0,0 +1,16 @@ +import sys +import os + +# Ajoute le chemin racine du projet +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +# tests/test_scan_ip.py +from scan_ip import check_port + +def test_check_port(): + # Test avec une adresse IP où le port 80 est fermé + assert not check_port("127.0.0.1", 80) + + # Test avec une adresse IP et un port connu pour être ouvert (Google DNS) + assert check_port("8.8.8.8", 53) +