From 3fed441a5be024232608cb9346f6e1a381101d4c Mon Sep 17 00:00:00 2001 From: Gilles Soulier Date: Sat, 4 Jan 2025 12:54:08 +0100 Subject: [PATCH] Augmentation du timeout et correction des tests --- scan_ip.py | 2 +- .../test_example.cpython-311-pytest-7.3.1.pyc | Bin 0 -> 1206 bytes .../test_scan_ip.cpython-311-pytest-7.3.1.pyc | Bin 0 -> 2412 bytes tests/ceciestuntest | 4 ---- tests/{test_example.py => test_example.py.old} | 0 tests/test_scan_ip.py | 16 ++++++++++++++++ 6 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 tests/__pycache__/test_example.cpython-311-pytest-7.3.1.pyc create mode 100644 tests/__pycache__/test_scan_ip.cpython-311-pytest-7.3.1.pyc delete mode 100644 tests/ceciestuntest rename tests/{test_example.py => test_example.py.old} (100%) create mode 100644 tests/test_scan_ip.py 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 0000000000000000000000000000000000000000..ce0700e4fd2cf60e5002186d0f7700c0399ee519 GIT binary patch literal 1206 zcma)4PjAyO6u0B_5Bnz}G+-Q1FQ7$8&BlOHK_@_P-Gy5(QHb4M)fiD3FBoqk=iBoTrdh3a2yR8x!XfN^e`#rz+v){AdFE1}3kdK!Jdkkxbh4rm1SGfhI7|$!l=&o^SB6I{pODSV^c9fz+$Ud4g z{38mVDvFe&XyqLlR-u9ltbN(th)^rqwc28NG%cA3&F2U>F7rGb0p1 zf9ty=S;|P(XW@y_Zd-VGdHu?IJlM2E<61*nTb8gI?Y6SF!6rF@WvRBL+8(aBLNK1F zfR-hsvt?ECg?sTJVIpx{o}YC*HwYZgV(vv@>~fZ$afI7t(vz>;R|J04d&GIf^K(u& z;-Q;3>>v)@o}0jmRm&HF(9wHs6v6c(xKRYRir}UOn)-IWB-u3B+z_(I4K0&9_R}b2 z_MRUEOxO=2uOG5rBJAhFizu^&=k^>wwq#~ zzMHF`%Kzswgw-zv&o^`RYXKH>ArY450jGgF{qG&M2dMsF)11Xk|6`A#Km?amf717Z z#P12+;5k}z^lND93xpeOa`uAz3A}{4E3Zv`d=c1G_dX!LChZHLCiS~vMEe2T;SGTD Z>53MpV}ddMDI0w9cZ@JTf09zvzX5k*1D1_bh*3PEXZCYp#xdg|(?M28d*_NY~#EhI~ zx4U3Mpx00ex%3c1Nm_C#rI1_cu}3d#Ak3-IlWzv!a_XBINs+vDNbjA|JiYh5znOh+ zv`^>fs|d#L?+vz}V}$rm_A zM>eG{iR(ca*Ox9ugR3U3ev>fuPXyF5=_QV|O?pKDD<(CoW5REZsWCMgv^Z&Vvck#L zp>eGt=HV*Ov6|%gZ}H8t$iU`4iw4%_p6AD2K$-4`J=>?O3TW)o*s=*bZ_%A_&vz{1 zM#S3o!%f?_0=w_Bibd@$m&5Gr=i;DV7<@@cNZ5k46_UOkTkhS+w*xx{jj6LUJe%C_ za$fi_FRbQ;jud3HYk8qV;ZmWx7_UBV?u31}x$XJBOPgPWy}iC0#I$*b_Cm*P(w-ey zUex4gqJmlp)QASGCXV|08%P!*F#n!Y{?*+_e`%Kw(&t6WOtj0>l+Uyo17@Jj+eidx z2F@bjE%J{rq#JmGIILnkC{4{{Z`}4T}H( literal 0 HcmV?d00001 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) +