Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. [Errno 110] Connection timed out
  2. Sending Key to Server
  3. Traceback (most recent call last):
  4. File "client.py", line 43, in <module>
  5. s.send(str(id))
  6. socket.error: [Errno 32] Broken pipe
  7.  
  8. import socket
  9. import os
  10. import subprocess
  11. from optparse import OptionParser
  12. from random import randint
  13.  
  14. # The Manager Address and port
  15.  
  16. host_ip='192.168.43.123'
  17. port =10106
  18.  
  19. # Generates a random number say xxxx then its client id becomes 'clxxxx' and home directory made at the server as '/home/clxxxx' with permissions 700
  20. def random_with_N_digits(n):
  21. range_start = 10**(n-1)
  22. range_end = (10**n)-1
  23. return randint(range_start, range_end)
  24.  
  25. id=random_with_N_digits(4)
  26. id="cl"+ str(id)
  27.  
  28. # Looks for a public key in .ssh folder if temp.pub not present. If not found generates a ssh public private key and sends it to manager which then copies it to the server
  29. subprocess.call(["bash","keygen.sh"])
  30.  
  31.  
  32. s = socket.socket()
  33. try:
  34. s.connect((host_ip,port))
  35. print "the socket has successfully connected to Backup Server IP == %s" %(host_ip)
  36.  
  37. except socket.error as err:
  38. print err
  39.  
  40. f = open('temp.pub','r')
  41. print "Sending Key to Server"
  42.  
  43. j = "-"
  44. s.send(str(id))
  45. l=f.read(8192)
  46. while(l):
  47. print 'Sending...'
  48. s.send(l)
  49. l = f.read(8192)
  50.  
  51. try:
  52. client_id=s.recv(1024)
  53. data=s.recv(12)
  54. ip=s.recv(24)
  55. print client_id,
  56. print data, ip
  57. except:
  58. print "An Unknown Error Occurred!"
  59.  
  60. f.close()
  61.  
  62. # Writes the parameters of client in the file 'backup_dir.txt'
  63. with open('backup_dir.txt','w') as the_file:
  64. the_file.write(client_id)
  65. the_file.write('n')
  66. the_file.write(data)
  67. the_file.write('n')
  68. the_file.write(ip)
  69. the_file.write('n')
  70. f.close()
  71.  
  72.  
  73. s.close()
  74.  
  75. import socket
  76. import subprocess
  77. import os
  78.  
  79. try:
  80. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  81. print "Socket has been successfully created"
  82. except socket.error as err:
  83. print "socket creation failed with error %s" %(err)
  84.  
  85. port = 10106
  86.  
  87. s.bind(('', port))
  88. print("socket binded to %s port" %port)
  89.  
  90. s.listen(10)
  91. print("socket is listening")
  92.  
  93. while(True):
  94. print("waiting for a connection")
  95. c, addr = s.accept()
  96. print("Got a connection from", addr,c)
  97. clientID =(c.recv(8192))
  98. key =(c.recv(8192))
  99. print clientID
  100. print key
  101.  
  102. with open("temp.pub", 'w') as fp:
  103. fp.write(key)
  104. note=subprocess.check_output("./test_user.sh "+ clientID, shell=True)
  105. note = str(note)
  106. print(len(note))
  107. flag, path, serverIP = note.split(":")
  108. print(flag)
  109. print(path)
  110. print(serverIP)
  111. if flag:
  112. c.send(clientID)
  113. c.send(path)
  114. c.send(serverIP)
  115. os.remove("temp.pub")
  116. else:
  117. c.send("Unable to add Client.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement