Programmation
Programmation TCP retour au college
Bonjour à toutes et à tous
j’ai mon script python qui va bien se connecter, récupere bien les deux nombres et renvoi le résultat
la réponse du serveur : [+] Good job ! Here is your flag : XXXXXXX
mais je fais quoi maintenant ?!!!
si j’execute mon programme depuis la fenetre je n’ai rien
et le bouton validation indique que je n’ai pas réussi
Merci de m’aider
c’est bon je ne mettais pas le flag dans la page !!!
Programmation TCP retour au college
why i can’t get a response back from the server ? here is my code :
import socket
import math
import re
import time
# Connection details
host = ’challenge01.root-me.org’
port = 52002
# Connect to the TCP server
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
try :
while True :
# Receive the calculation task from the server
data = sock.recv(1024).decode()
print("Received :", data)
# Extract the numbers using regex from the specific line containing the calculation
match = re.search(r’Calculate the square root of (\d+) and multiply by (\d+) =’, data)
if match :
number1 = float(match.group(1)) # First number
number2 = float(match.group(2)) # Second number
# Calculate the result
result = math.sqrt(number1) * number2
result = round(result, 2)
print("Calculated result :", result)
# Send the result back to the server
sock.sendall(str(result).encode())
print("Sent result :", result)
# Receive and print the server’s response
response = sock.recv(1024).decode()
print("Response :", response)
# Check if the response contains the flag or success message
if "Good job !" in response :
print("Congratulations ! Here is your flag :", response.split(" :")[-1].strip())
break # Exit the loop after receiving the flag
else :
print("Could not find the numbers in the expected format.")
except socket.error as e :
print("Socket error :", e)
except Exception as e :
print("Error :", e)
finally :
# Close the connection
sock.close()