Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import *
- import sys
- import select
- import hashlib
- host="0.0.0.0"
- port = 9999
- s = socket(AF_INET,SOCK_DGRAM)
- s.bind((host,port))
- addr = (host,port)
- buf=1024
- data,addr = s.recvfrom(buf)
- print "Received File:",data.strip()
- f = open(data.strip(),'wb')
- data,addr = s.recvfrom(buf)
- try:
- while(data):
- f.write(data)
- s.settimeout(2)
- data,addr = s.recvfrom(buf)
- except timeout:
- f.close()
- s.close()
- print "File Downloaded"
- file_name= raw_input("Enter file name: ")
- desired_hash= raw_input("Enter desired hash: ")
- BLOCKSIZE = 65536
- hasher = hashlib.sha1()
- with open(file_name, 'rb') as afile:
- buf = afile.read(BLOCKSIZE)
- while len(buf) > 0:
- hasher.update(buf)
- buf = afile.read(BLOCKSIZE)
- current_hash=hasher.hexdigest()
- if(desired_hash==current_hash):
- print "File is intact"
- else:
- print "File is broken"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement