Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. def main():
  2.     getConnection();
  3.  
  4. def getConnection():
  5.     import socket;
  6.     import time;
  7.  
  8.     host = socket.gethostbyname(socket.gethostname());
  9.     port = 1024;
  10.  
  11.     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as socket:
  12.         socket.bind((host, port));
  13.         socket.listen();
  14.  
  15.         print("---------------------------------------------------------------");
  16.         print("[*] IP: {}.".format(host) + "\n[*] Porta: {}.".format(port));
  17.         print("[*] Inicializando o servidor, por favor aguarde um instante...");
  18.         print("---------------------------------------------------------------");
  19.  
  20.         time.sleep(3);
  21.  
  22.         print("[*] Servidor iniciado. Aguardando conexão...");
  23.         print("---------------------------------------------------------------");
  24.  
  25.         while True:
  26.             connection, address = socket.accept();
  27.             print("[!] Conexão recebida de {}, com porta {}.".format(address[0], address[1]));
  28.             print("---------------------------------------------------------------");
  29.  
  30. if(__name__ == "__main__"):
  31.     main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement