簡體   English   中英

如何在 Python 中使用 SSH 連接從遠程主機發送 GET 請求?

[英]How to send GET request from remote host using SSH connection in Python?

如何從連接的遠程主機發送 GET 請求。 我通過CMD試過了。首先我登錄到ssh root,然后發送這個請求:

curl -X GET "https://bsms.its.com.pk/otpsms.php?key=xxxxx&receiver=xxx&sender=xxxx&param1=uxxser&otpcode=1234"

有用。 我正在嘗試在我的 python flask 中做同樣的事情,但它不起作用。

username = 'root'
hostname = '175.111.0.26'
port = 22
password='passowrd'


def do_it():
    s = paramiko.SSHClient()
    s.load_system_host_keys()
    s.connect(hostname, port, username, password)
    command = "https://bsms.its.com.pk/otpsms.php?key=xxx&receiver=number&sender=xxxx&param1=xxx&otpcode=1234"
    command.request("GET", '/')
    s.exec_command(command)
    print(command)
   
    s.close()

那這個呢?

 # Connect to the remote host client = paramiko.SSHClient() client.load_system_host_keys() client.connect(hostname, username=username, password=password) # Send the GET request using the `curl` command stdin, stdout, stderr = client.exec_command('curl ' + url) # Print the response print(stdout.read()) # Close the connection client.close()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM