원격 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.
* pynacl *이 (가) 설치되지 않았습니다. 괜찮습니다. 확장 모듈 중 하나 (또는 일부 * .dll * 종속성)를 찾을 수 없습니다. 당신은 단순히 'import paramiko'에 의해 문제를 재현 할 수 있어야합니다. BTW : * Python37 *은 경로에 있습니까? – CristiFati
@CristiFati : 내가 어디서 파이썬을 만들었고 D : \ Users \ prashant-gu \ AppData \ Local \ Programs \ Python \ Python37 \ python.exe \ –
경로를 받았습니다. @CristiFati : 당신이 나에게 준 단서 . 많은 노력이 필요했으나 마침내 문제가 해결되었습니다. –