Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import time
- # create a socket object
- serversocket = socket.socket(socket.AF_INET,
- socket.SOCK_STREAM)
- # get local machine name
- host = socket.gethostname()
- port = 4000
- # bind to the port
- serversocket.bind((host, port))
- # queue up to 5 requests
- serversocket.listen(5)
- print("Servidor", host, "esperando conexão na porta", port)
- while True:
- # establish a connection
- clientsocket,addr = serversocket.accept()
- print("Got a connection from %s" % str(addr))
- currentTime = time.ctime(time.time()) + "rn"
- clientsocket.send(currentTime.encode('ascii'))
- clientsocket.close()
- # client.py
- import socket
- import platform
- # create a socket object
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # get local machine name
- host = socket.gethostname()
- port = 4000
- # connection to hostname on the port.
- s.connect((host, port))
- # Receive no more than 1024 bytes
- tm = s.recv(1024)
- x = ip = s.getsockname()
- sis = platform.system()
- #***************** Opções ***************************
- print("******************************************")
- print("Comandos: n 1 - Data n 2 - Rede n 3 - Sistema n 0 - Terminar Conexão atual")
- print("******************************************")
- co = "oi"
- while (co != "0"):
- co = input(str("Digite o comando: "))
- if co == "1":
- print("A data e hora atual do servidor é %s n" % tm.decode('ascii'))
- if co == "2":
- print(" Nome do host: {} n IP e Porta do Cliente: {} n".format(host, x))
- if co == "3":
- print("Sistema Operacional: {} n".format(sis))
- s.close()
- import platform
- import socket
- import html
- from flask import Flask, request, render_template # importa a classe Flask
- # create a socket object
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # get local machine name
- host = socket.gethostname()
- port = 4000
- # connection to hostname on the port.
- s.connect((host, port))
- # Receive no more than 1024 bytes
- tm = s.recv(1024)
- x = ip = s.getsockname()
- sis = platform.system()
- s.close()
- app = Flask(__name__)
- @app.route('/', methods=['POST'])
- def my_form():
- if request.method == 'POST':
- return render_template("form.html")
- elif request.method == 'GET':
- return render_template("form.html")
- if __name__ == "__main__":
- app.run(host='0.0.0.0', port=4000)
Add Comment
Please, Sign In to add comment