TCP - Retour au collège
Rédaction d'un script python
import socket
import re
from math import *
def netcat(HOST,PORT):
# Create a socket object
s = socket.socket()
# connect to the server on local computer
s.connect((HOST, PORT))
# receive data from the server and decoding to get the string.
res = s.recv(1024).decode()
print(res)
# read number
regex = "([0-9]+)"
# Search regex
search = re.findall(regex, res)
# caclul square
first_res = sqrt(int(search[1]))
print(f'The first res : {first_res}')
# second calcul
second_res = first_res * int(search[2])
print(f'The second res : {second_res}')
# round the result
round_res = round(second_res,2)
print(f'The last res : {round_res}')
# send result
s.sendall((str(round_res)+"\n").encode())
return s.recv(1024).decode()
def main():
print(netcat("challenge01.root-me.org",52002))
if __name__ == "__main__":
main()
Flag :
RM{TCP_C0nnecT_4nD_m4Th}