通过部署好的DJANGO服务器执行WINDOWS命令

dbs2.py

import wmi

def run(host,uname,pwd,cmd):

    c = wmi.WMI(computer=host, user=uname, password=pwd)
    c.Win32_Process.Create(CommandLine=cmd)


views.py

def run(request):

 if request.method=="POST":
        try:
            cmd=request.POST.get("cmd")
            ip=request.POST.get("ip")
            uname=request.POST.get("uname")
            pwd=request.POST.get("pwd")
            dbs2.run(ip,uname,pwd,cmd)
            return render(request,"run.html",{"login_err":"okay"})
        except Exception:
            return render(request,"run.html",{"login_err":"fail"})
    else:
        return render(request,"run.html",{"login_err":"noset"})


run.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form id="loginForm" action="{% url 'run' %}" method="POST"> {% csrf_token %}
IP地址<input type="text" class="form-control" name="ip" placeholder="IP地址"></br>
用户名<input type="text" class="form-control" name="uname" placeholder="用户名"></br>
密码<input type="password" class="form-control" name="pwd" placeholder="连接密码"></br>
    执行命令<input type="text" class="form-control" name="cmd" placeholder="命令"></br>
<button class="btn btn-success btn-block" type="submit">
<b>确定执行</b>
</button>


<h4 style="color: red"><b>{{ login_err }}</b></h4>
    </form>
</body>
</html>

urls.py

加入

url(r'^run/$',views.run,name='run'),


猜你喜欢

转载自blog.csdn.net/lsysafe/article/details/79257773