Advertisement
Guest User

Untitled

a guest
Feb 11th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. # telnet program example
  2. import socket, select, string, sys
  3. import time
  4. #main function
  5. if __name__ == "__main__":
  6.  
  7. if(len(sys.argv) < 3) :
  8. print 'Usage : python telnet.py hostname port'
  9. sys.exit()
  10.  
  11. host = sys.argv[1]
  12. port = int(sys.argv[2])
  13.  
  14. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  15. s.settimeout(200)
  16.  
  17. # connect to remote host
  18. try :
  19. s.connect((host, port))
  20. except :
  21. print 'Unable to connect'
  22. sys.exit()
  23.  
  24. print 'Connected to remote host'
  25.  
  26. while 1:
  27. socket_list = [sys.stdin, s]
  28.  
  29. # Get the list sockets which are readable
  30. read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
  31.  
  32. for soc in read_sockets:
  33. #incoming message from remote server
  34. if soc == s:
  35. flag=""
  36. maxi=0.000
  37. dico=['1','2','3','4','5','6','7','8','9','0','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','.','-','#','!',',',';',':','@']
  38. for c in dico:
  39. print (flag+c)
  40. first_time = time.time()
  41. soc.send(flag + c)
  42. print (soc.recv(4096))
  43. last_time = time.time()-first_time
  44. print last_time
  45. if last_time>maxi:
  46. maxi=last_time
  47. print "Bonne lettre ---------------------------------"
  48. if not data :
  49. print 'Connection closed'
  50. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement