Advertisement
Guest User

host.py

a guest
Jan 26th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import os
  2. import socket
  3. import time
  4. import threading
  5.  
  6. os.system("clear")
  7.  
  8. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9.  
  10. def repeat_connect(host, port):
  11. s.listen(1)
  12. conn, addr = s.accept()
  13. with conn:
  14. print("Connection from: [%s: %s]" % (addr))
  15. while True:
  16. data = conn.recv(1024)
  17. if not data: break
  18. conn.send(data)
  19.  
  20.  
  21. def create_server(host, port):
  22. os.system("clear")
  23. print("\nAttempting to create server on\nIP: %s\nPort: %s" % (host, port))
  24. s.bind((host, port))
  25. os.system("clear")
  26. print("\nServer successfully created on:\nIP: %s\nPort: %s" % (host, port))
  27. s.listen(10)
  28. #conn, addr = s.accept()
  29. #with conn:
  30. # while True:
  31. # print("Connection from: [%s: %s]" % (addr))
  32. # data = conn.recv(1024)
  33. # if not data: break
  34. # conn.send(data)
  35. while True:
  36. s.listen(1)
  37. conn, addr = s.accept()
  38. print("\nConnection from: [%s: %s]" % (addr))
  39. with conn:
  40. data = conn.recv(1024)
  41. if not data: break
  42. conn.send(data)
  43.  
  44.  
  45.  
  46. def get_server_info():
  47. while True:
  48. os.system("clear")
  49. os.system("hostname -I")
  50.  
  51. print("\nWhich IP and Port would you like to create the server on?")
  52. host = input("\nIP: ")
  53. port = int(input("Port: ")) # port number has to be int (incase the int(intput)) was confusing...
  54.  
  55. os.system("clear")
  56.  
  57. print("\nIP: %s\nPort: %s" % (host, port))
  58. print("\nIs the information you'd like to create the server on correct?")
  59. correct = input("\n[y/n]: ").lower().split()
  60.  
  61. if correct[0] == "y":
  62. create_server(host, port)
  63. elif correct[0] == "n":
  64. get_server_info()
  65. else:
  66. get_server_info()
  67.  
  68. get_server_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement