2017-11-21 4 views
1

원격 SSH 서버에 연결하기 위해 Windows에서 스크립트를 만들었습니다. cryptography, pynacl 그리고 마지막으로 paramiko (성공적으로 Windows에 설치하는 방법을 파악하기 위해 하루 종일 사용)을 성공적으로 설치했습니다.Windows에 파이썬의 암호화 설치

이제 스크립트를 실행하면 DLL 로딩이 실패했다는 오류 메시지가 나타납니다. 이 오류는 libsodium과 관련이있는 것 같지만 어떤 DLL을로드하려고하는지 정확히 알 수 없습니다. 더 안전한쪽에 있으려면 pysodium도 설치해야합니다.

다음은 스크립트의 :

automate.py

import SSH 

connection = ssh("10.10.65.100", "gerrit2", "[email protected]") 
print("Calling OpenShell") 
connection.openShell() 
print("Calling sendShell") 
connection.sendShell("ls -l") 
print("Calling process") 
connection.process() 
print("Calling closeConnection") 
connection.closeConnection() 

SSH.py

import threading, paramiko 

class ssh: 
    shell = None 
    client = None 
    transport = None 

    def __init__(self, address, username, password): 
     print("Connecting to server on ip", str(address) + ".") 
     self.client = paramiko.client.SSHClient() 
     self.client.set_missing_host_key_policy(paramiko.client.AutoAddPolicy()) 
     self.client.connect(address, username=username, password=password, look_for_keys=False) 
     self.transport = paramiko.Transport((address, 22)) 
     self.transport.connect(username=username, password=password) 

     thread = threading.Thread(target=self.process) 
     thread.daemon = True 
     thread.start() 

    def closeConnection(self): 
     if(self.client != None): 
      self.client.close() 
      self.transport.close() 

    def openShell(self): 
     self.shell = self.client.invoke_shell() 

    def sendShell(self, command): 
     if(self.shell): 
      self.shell.send(command + "\n") 
     else: 
      print("Shell not opened.") 

    def process(self): 
     global connection 
     while True: 
      # Print data when available 
      if self.shell != None and self.shell.recv_ready(): 
       alldata = self.shell.recv(1024) 
       while self.shell.recv_ready(): 
        alldata += self.shell.recv(1024) 
       strdata = str(alldata, "utf8") 
       strdata.replace('\r', '') 
       print(strdata, end = "") 
       if(strdata.endswith("$ ")): 
        print("\n$ ", end = "") 

그리고 여기 오류입니다 : 나는 마침내 this 우연히 인터넷 검색을 많이 후

> python automate.py 

Traceback (most recent call last): 
    File "automate.py", line 1, in <module> 
    import SSH 
    File "D:\Automate\SSH_Paramiko\SSH.py", line 1, in <module> 
    import threading, paramiko 
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\__init__.py", line 22, in <module> 
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\transport.py", line 57, in <module> 
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko-2.4.0-py3.7.egg\paramiko\ed25519key.py", line 22, in <module> 
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\signing.py", line 19, in <module> 
    import nacl.bindings 
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\bindings\__init__.py", line 17, in <module> 
    from nacl.bindings.crypto_box import (
    File "D:\Users\prashant-gu\AppData\Local\Programs\Python\Python37\lib\site-packages\nacl\bindings\crypto_box.py", line 18, in <module> 
    from nacl._sodium import ffi, lib 
ImportError: DLL load failed: The specified module could not be found. 
+0

* pynacl *이 (가) 설치되지 않았습니다. 괜찮습니다. 확장 모듈 중 하나 (또는 ​​일부 * .dll * 종속성)를 찾을 수 없습니다. 당신은 단순히 'import paramiko'에 의해 문제를 재현 할 수 있어야합니다. BTW : * Python37 *은 경로에 있습니까? – CristiFati

+0

@CristiFati : 내가 어디서 파이썬을 만들었고 D : \ Users \ prashant-gu \ AppData \ Local \ Programs \ Python \ Python37 \ python.exe \ –

+0

경로를 받았습니다. @CristiFati : 당신이 나에게 준 단서 . 많은 노력이 필요했으나 마침내 문제가 해결되었습니다. –

답변

0

. 나는 내 이전 pynacl 설치를 제거 대화에서 언급 한 바와 같이, https://github.com/lmctv/pynacl/archive/v1.2.a0.reorder.zip에서 압축 된 소스를 다운로드 https://github.com/jedisct1/libsodium/releases/download/1.0.15/libsodium-1.0.15.tar.gz에서 libsodium 다운로드, D:\Users\prashant-gu\Downloads\libsodium-1.0.15\bin\x64\Release\v140\dynamicLIB 환경 변수를 설정하고, 마지막으로

pip install .

지금 사용하여이 다운로드 소스를 형성 pynacl 설치 그것은 잘 작동합니다. paramiko를 설치하는 동안

, 나는 또한 https://ci.cryptography.io/job/cryptography-support-jobs/job/openssl-release-1.1/에서 OpenSSL을 다운로드하는 일이, 그리고 설정이 성공적으로 paramiko에 대한 종속성으로 일어나는 cryptography 패키지를 설치하기 위해 D:\Users\prashant-gu\Downloads\openssl-1.1.0g-2015-x86_64\openssl-win64-2015\include에 환경 변수를 포함합니다.