1

For some reason, the output returns like this instead of how it should be: Listed; one under the other; organized.

Reference: https://i.stack.imgur.com/HkKDZ.png

consulta.py

from socket import socket, AF_INET, SOCK_STREAM
from sys import argv
import pyfiglet

ascii_banner = pyfiglet.figlet_format("WHOIS - Gustang")
print (ascii_banner)

host = 'whois.iana.org'
port = 43
conn = host, port
crlf = b'\r\n'
bufsiz = 2172

if len(argv) == 2:

        with socket(AF_INET, SOCK_STREAM) as s:
                s.connect(conn)
                ba = bytearray()
                ba.endswith(crlf)
                s.send(f'{argv[1]}\r\n'.encode())
                resp = s.recv(bufsiz)
                print (resp)

Gustang
  • 21
  • 2
  • 1
    Are you sure it hangs? It could be waiting on a timeout on the socket operations. Add a couple print statements in your code to see exactly where it hangs. – Nic3500 Jun 02 '23 at 14:48
  • I achieved. However, it does not read /r/n as it should, here is the print: (https://uploaddeimagens.com.br/imagens/0nHL1XM) – Gustang Jun 02 '23 at 18:14
  • You should put extra details in the question, cut-paste the text in here. I will not click on external links (.br ? Brazil?) – Nic3500 Jun 02 '23 at 18:25
  • Yes I'm brazilian. I edited the post code to what worked. – Gustang Jun 02 '23 at 19:08

1 Answers1

0

Your output looks to be raw bytes (notice the b in front). The recv returns the raw bytes: https://docs.python.org/3/library/socket.html#socket.socket.recv My guess would be that casting it to a string print(resp.decode("utf-8")) will render the "\r\n" correctly. See Convert bytes to a string

Dumbo
  • 55
  • 8