Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # telnet program example
- import socket, select, string, sys
- import time
- #main function
- if __name__ == "__main__":
- if(len(sys.argv) < 3) :
- print 'Usage : python telnet.py hostname port'
- sys.exit()
- host = sys.argv[1]
- port = int(sys.argv[2])
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- s.settimeout(200)
- # connect to remote host
- try :
- s.connect((host, port))
- except :
- print 'Unable to connect'
- sys.exit()
- print 'Connected to remote host'
- while 1:
- socket_list = [sys.stdin, s]
- # Get the list sockets which are readable
- read_sockets, write_sockets, error_sockets = select.select(socket_list , [], [])
- for soc in read_sockets:
- #incoming message from remote server
- if soc == s:
- flag=""
- maxi=0.000
- 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','.','-','#','!',',',';',':','@']
- for c in dico:
- print (flag+c)
- first_time = time.time()
- soc.send(flag + c)
- print (soc.recv(4096))
- last_time = time.time()-first_time
- print last_time
- if last_time>maxi:
- maxi=last_time
- print "Bonne lettre ---------------------------------"
- if not data :
- print 'Connection closed'
- sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement