Guest User

Untitled

a guest
Mar 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. import socket
  2. import time
  3. # create a socket object
  4. serversocket = socket.socket(socket.AF_INET,
  5. socket.SOCK_STREAM)
  6. # get local machine name
  7. host = socket.gethostname()
  8. port = 4000
  9. # bind to the port
  10. serversocket.bind((host, port))
  11. # queue up to 5 requests
  12. serversocket.listen(5)
  13. print("Servidor", host, "esperando conexão na porta", port)
  14. while True:
  15. # establish a connection
  16. clientsocket,addr = serversocket.accept()
  17. print("Got a connection from %s" % str(addr))
  18. currentTime = time.ctime(time.time()) + "rn"
  19. clientsocket.send(currentTime.encode('ascii'))
  20. clientsocket.close()
  21.  
  22. # client.py
  23. import socket
  24. import platform
  25. # create a socket object
  26. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  27. # get local machine name
  28. host = socket.gethostname()
  29. port = 4000
  30. # connection to hostname on the port.
  31. s.connect((host, port))
  32. # Receive no more than 1024 bytes
  33. tm = s.recv(1024)
  34. x = ip = s.getsockname()
  35. sis = platform.system()
  36.  
  37.  
  38. #***************** Opções ***************************
  39. print("******************************************")
  40. print("Comandos: n 1 - Data n 2 - Rede n 3 - Sistema n 0 - Terminar Conexão atual")
  41. print("******************************************")
  42.  
  43. co = "oi"
  44.  
  45. while (co != "0"):
  46. co = input(str("Digite o comando: "))
  47. if co == "1":
  48. print("A data e hora atual do servidor é %s n" % tm.decode('ascii'))
  49. if co == "2":
  50. print(" Nome do host: {} n IP e Porta do Cliente: {} n".format(host, x))
  51. if co == "3":
  52. print("Sistema Operacional: {} n".format(sis))
  53.  
  54. s.close()
  55.  
  56. import platform
  57. import socket
  58. import html
  59. from flask import Flask, request, render_template # importa a classe Flask
  60.  
  61. # create a socket object
  62. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  63. # get local machine name
  64. host = socket.gethostname()
  65. port = 4000
  66. # connection to hostname on the port.
  67. s.connect((host, port))
  68. # Receive no more than 1024 bytes
  69. tm = s.recv(1024)
  70. x = ip = s.getsockname()
  71. sis = platform.system()
  72. s.close()
  73.  
  74.  
  75. app = Flask(__name__)
  76.  
  77.  
  78. @app.route('/', methods=['POST'])
  79. def my_form():
  80. if request.method == 'POST':
  81. return render_template("form.html")
  82. elif request.method == 'GET':
  83. return render_template("form.html")
  84.  
  85. if __name__ == "__main__":
  86. app.run(host='0.0.0.0', port=4000)
Add Comment
Please, Sign In to add comment