标签:ofo int argv lse htm port href salt cat
#-- coding:utf-8 --import requests
import json
import urllib3
import sys
#首先获得salt的token
def Get_token():
#准备请求头等各种信息
urllib3.disable_warnings()
URL = ‘https://172.16.185.232/login/‘
Hander = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36",
"Content-type": "application/json"}
Info = {‘username‘:‘salt‘,‘password‘:‘1P9lS57ZaJ59FFdayuiX‘,‘eauth‘:‘pam‘}
request = requests.post(url=URL,data=Info,verify=False)
response = request.json()
return response[‘return‘][0][‘token‘]
def salt_command():
urllib3.disable_warnings()
tgt = sys.argv[1]
arg = sys.argv[2]
Url = ‘https://172.16.185.232‘
Hander = {‘X-Auth-Token‘:Get_token()}
Data = {‘client‘: ‘local‘, ‘tgt‘: tgt,‘fun‘: ‘cmd.run‘,‘arg‘:arg}
ret = requests.post(url=Url,data=Data,headers=Hander,verify=False)
print(ret.json())
if name == ‘main‘:
salt_command()
标签:ofo int argv lse htm port href salt cat
原文地址:http://blog.51cto.com/2925718/2176013