Skip to content

Instantly share code, notes, and snippets.

@vivosmith
Created August 18, 2016 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vivosmith/ff809cc12c97aa14ac987e2f87846981 to your computer and use it in GitHub Desktop.
Save vivosmith/ff809cc12c97aa14ac987e2f87846981 to your computer and use it in GitHub Desktop.
import socket
s = socket.socket()
host = socket.gethostname()
port = 1231
s.connect((host, port))
print (s.recv(1024))
filename=input('Choose the file')
filez=''.join(filename)
s.send(filez.encode())
l = s.recv(1024)
has='has'
j = open(filez,"wb+")
j.read()
j.write(l)
j.close()
s.close()
import socket
from os import listdir
import os
import random
invite=random.randint(1,100000)
key=random.randint(1,1000000)
combinedkey=str(key) + str(invite) + "\n"
keyfile=open('keylist.txt', 'a')
keyfile.write(combinedkey)
keyfile.close()
commondirectory='/home/communaldump/'
files=os.listdir(commondirectory)
filelist=''.join(files)
s=socket.socket()
host=socket.gethostname()
port=1231
s.bind((host,port))
s.listen(5)
while True:
conn,addr=s.accept()
print 'got connection from'
print "%s" % (addr,)
conn.send('Thank you for connecting')
conn.send("\n")
conn.send(filelist)
data = conn.recv(1024)
print "%s" % data
sdata=commondirectory+data
f=open(sdata,"rb+")
l=f.read()
conn.send(l)
f.close()
conn.close()
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment