Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- import os
- import time
- os.system("clear")
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- def connect(host, port):
- print("\nAttempting to connect to:\nIP: %s\nPort: %d" % (host, port))
- s.connect((host,port))
- print("\nSuccessfully connected to:\nIP: %s\nPort: %d" % (host, port))
- name = input("\nWhats your name?\nName: ")
- while True:
- message = input("%s: " % (name)).encode()
- s.sendall(message)
- data = s.recv(1024)
- print("Received: ", repr(data))
- def get_connection_info():
- while True:
- os.system("clear")
- os.system("hostname -I")
- print("\nWhat IP and Port would you like to connect to?")
- host = input("\nHost: ")
- port = int(input("Port: ")) # the port has to be an int, (explaining the reasoning behind the int(input))
- os.system("clear")
- print("\nIs this the correct IP and Port number you'd like to connect to?\n\nIP: %s\nPort: %d" % (host, port))
- correct = input("\n[y/n]: ").lower().split()
- if correct[0] == "y":
- connect(host, port)
- elif correct[0] == "n":
- get_connection_info()
- else:
- get_connection_info()
- get_connection_info()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement