Skip to content

Instantly share code, notes, and snippets.

Created August 15, 2016 21:12
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 anonymous/8f70b3e2eca8606dee2c245ce64e9b63 to your computer and use it in GitHub Desktop.
Save anonymous/8f70b3e2eca8606dee2c245ce64e9b63 to your computer and use it in GitHub Desktop.
Client server combo
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())
f = open("texan.txt","wb+")
l = s.recv(1024)
print ("%s" % l)
while (l):
lm=str(l)
print (lm)
f.write(lm)
f.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,"wb+")
l=f.read(1024)
print l
while l:
conn.sendall(l)
data = conn.recv(1024)
f.close()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment