Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python
- # -*- coding: utf-8 -*-
- import socket, sys , hashlib, struct
- unpacker = struct.Struct('6s 6s')
- packer = struct.Struct('6s 6s')
- server_address = ('localhost', 10000)
- #File open and output
- filename1='text1.txt'
- f1 = open(filename1,'r')
- text1 = f1.read()
- filename2='text2.txt'
- f2 = open(filename2,'r')
- text2 = f2.read()
- print '=========================================='
- print 'Text1 is :'
- print text1
- print '========================================='
- print 'Text2 is :'
- print text2
- print '=========================================\n'
- #Hash creation and output
- h = hashlib.sha1()
- h.update(text1)
- hash_text1_client= h.hexdigest()
- h.update(text2)
- hash_text2_client= h.hexdigest()
- print '=========================================='
- print 'Hash for Text1 is :'
- print hash_text1_client
- print '========================================='
- print 'Hash for Text2 is :'
- print hash_text2_client
- print '=========================================\n'
- #Connection with the server
- print >>sys.stderr, 'Trying to connect to %s:%s' % server_address
- try:
- sock_auth = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock_auth.connect(server_address)
- except:
- print 'Could not connect to the server.'
- sys.exit(0)
- print 'Connection Successful.'
- #Auth step
- authenticated_successfully="False"
- kicked_out="False"
- while ( authenticated_successfully !="True" ) :
- input_username=raw_input('Enter your username :')
- input_password=raw_input('Enter your password :')
- input_credentials = (input_username,input_password)
- input_packed_data = packer.pack(*input_credentials)
- sock_auth.sendall(input_packed_data)
- authenticated_successfully=sock_auth.recv(4)
- kicked_out=sock_auth.recv(4)
- if (kicked_out=="True") :
- sys.exit(0)
- sock_auth.close()
- try:
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect(server_address)
- sock.sendall(text1)
- sock.close()
- sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock2.connect(server_address)
- sock2.sendall(text2)
- sock2.close()
- sock_hash = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock_hash.connect(server_address)
- sock_hash.sendall(hash_text1_client)
- sock_hash.sendall(hash_text2_client)
- sock_hash.close()
- sock3 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock3.connect(server_address)
- result=''
- while True:
- data = sock3.recv(16)
- print >>sys.stderr, 'Received "%s" from data1' % result
- if data:
- result+=data
- else:
- break
- print 'Data Received Successfully.\n'
- print result
- finally:
- print 'All done \n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement