Advertisement
Guest User

Untitled

a guest
Feb 14th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. Traceback (most recent call last):
  2. File "<string>", line 56, in <module>
  3. File "c:Python27Scriptsbuildinstall_squidout00-PYZ.pyzparamiko.transport", line 211, in __init__
  4. socket.gaierror: [Errno 11001] getaddrinfo failed
  5.  
  6. import paramiko
  7. import csv
  8. import datetime
  9. import os,time
  10.  
  11. def times():
  12. today = str(datetime.datetime.today()).split(' ')
  13. time=today[1].split('.')
  14. t=""+today[0]+' '+time[0]+''
  15. return t
  16.  
  17. if __name__=="__main__":
  18. print "Time : %s"%times()
  19. path=os.path.dirname(os.path.abspath(__file__))
  20.  
  21. conf=open(os.path.join(path,'conf.txt'),'r').readlines()
  22. proxyUsername=str(str(conf[0]).split('=')[1]).strip()
  23. proxyPassword=str(str(conf[1]).split('=')[1]).strip()
  24. proxyPort=str(str(conf[2]).split('=')[1]).strip()
  25. proxySh=open(os.path.join(path,'proxy.sh'),'r').read()
  26. proxySh=proxySh.replace('user=','user=%s'%(str(proxyUsername))).replace('pass=','pass=%s'%(str(proxyPassword))).replace('port=','port=%s'%(str(proxyPort)))
  27. open(os.path.join(path,'proxy2.sh'),'wb').write(proxySh)
  28. time.sleep(1)
  29. squidSh=open(os.path.join(path,'squid.conf'),'r').read()
  30. squidSh=squidSh.replace('http_port 0.0.0.0:','http_port 0.0.0.0:%s'%(str(proxyPort)))
  31. open(os.path.join(path,'squid2.conf'),'wb').write(squidSh)
  32. time.sleep(1)
  33. with open('servers.csv', 'rb') as csvfile:
  34. reader = csv.reader(csvfile)
  35. your_list = list(reader)
  36.  
  37. for item1 in your_list:
  38. host = item1[0]
  39. username = item1[1]
  40. password = item1[2]
  41. port = 22
  42.  
  43. pathProxy = '/usr/src/proxy.sh'
  44. proxy = os.path.join(path,'proxy2.sh')
  45. pathConfig = '/usr/src/squid.conf'
  46. config = os.path.join(path,'squid2.conf')
  47. transport = paramiko.Transport((host, port))
  48. transport.connect(username = username, password = password)
  49. sftp = paramiko.SFTPClient.from_transport(transport)
  50. sftp.put(proxy, pathProxy)
  51. sftp.put(config, pathConfig)
  52. sftp.close()
  53. transport.close()
  54. print "Copied SquidProxy Script To Server " + "........" + host
  55. ssh = paramiko.SSHClient()
  56. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  57. ssh.connect(host, username=username, password=password, port=22)
  58. print "Installing SquidProxy Script To Server " + "........" + host
  59. #
  60. sleeptime = 0.001
  61. outdata, errdata = '', ''
  62. ssh_transp = ssh.get_transport()
  63. chan = ssh_transp.open_session()
  64. # chan.settimeout(3 * 60 * 60)
  65. chan.setblocking(0)
  66. chan.exec_command('cd /usr/src && sh proxy.sh')
  67. while True: # monitoring process
  68. # Reading from output streams
  69. while chan.recv_ready():
  70. outdata += chan.recv(1000)
  71. while chan.recv_stderr_ready():
  72. errdata += chan.recv_stderr(1000)
  73. if chan.exit_status_ready(): # If completed
  74. break
  75. time.sleep(sleeptime)
  76. retcode = chan.recv_exit_status()
  77. ssh_transp.close()
  78.  
  79. print(outdata)
  80. for x in str(outdata).splitlines():
  81. if proxyPassword in x:
  82. open(os.path.join(path,'proxies.txt'),'a').write(x+'n')
  83. os.remove(os.path.join(path,'squid2.conf'))
  84. os.remove(os.path.join(path,'proxy2.sh'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement