Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. import sys, socket, traceback, telnetlib as telnet
  2.  
  3. def openconn():
  4. temp=0
  5. while temp==0:
  6. try:
  7. ip = str(input("What ip would you like to connect to?"))
  8. port = input("And what port would you like to connect to?")
  9.  
  10.  
  11. global conn
  12. conn=telnet.Telnet(ip,port,1)
  13. print("Connected")
  14. temp=1
  15. break
  16.  
  17. except:
  18. print("please ensure that you're entering a correct ip and port")
  19.  
  20. def communicate():
  21.  
  22. temp = 0
  23. while temp==0:
  24. try:
  25. sndmsg = input("Message:")
  26. sndmsg = bytes(sndmsg, "ascii")
  27.  
  28. if sndmsg == b"close":
  29. conn.close()
  30. print("Connection closed")
  31. temp=1
  32. break
  33.  
  34. conn.write(sndmsg+b"\n")
  35. print(conn.read_all())
  36.  
  37. except BrokenPipeError:
  38. print("Connection closed")
  39. temp=1
  40.  
  41. except:
  42. print("Something went wrong.")
  43. print(traceback.print_exc())
  44.  
  45. temp2 = 0
  46.  
  47. while temp2 ==0:
  48. temp3 = input("Would you like to try again? (y/n)")
  49.  
  50. if temp3 is not 'y' and temp3 is not 'Y' and temp3 is not 'n' and temp3 is not 'N':
  51. print("You entered an incorrect key!")
  52.  
  53. if temp3 is 'y' or temp3 is 'Y':
  54. temp2=1
  55.  
  56. if temp3 is 'n' or temp3 is 'N':
  57. temp = 1
  58. temp2 = 1
  59.  
  60. while True:
  61. openconn()
  62. communicate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement