【原创】jumpsever 堡垒机 api https登录 python ssl https post 验证登录,获取堡垒机token

2026-06-23 04:46:1921 阅读量

为了方便公司同事 申请堡垒机账号和开通相应的权限。省去每次人工去添加账号的麻烦

相关服务:马来西亚服务器

就用fastadmin + python +jumpserver+API 做了一个自助系统,通过公司邮箱填写账号和选择权限,申请成功,发送邮件到公司邮箱,管理人员审批激活权限。

import urllib
import urllib.parse
import urllib.request
from http.client import HTTPSConnection
import ssl


myhost ="hlwblj.xxxxxxxxxx.com" #堡垒机地址

ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
#建立连接,获取服务器的公开密钥

conn = HTTPSConnection(host=myhost, context=ctx)

#通过Http协议访问,我们需要访问的Https,并得到返回的代码
#根据需要可以模拟https请求的header,cookie等

data = '{"username": "user*********", "password": "passwd*********"}'.encode("utf-8")# 对数据进行url编码及utf-8编码
headers = {"Content-Type": "application/json"}

conn.request('POST', '/api/v1/authentication/auth/', data,headers) #堡垒机API接口地址

res = conn.getresponse()

print(res.read().decode('utf-8'))

本文地址:https://www.idc504.com/news/9_160910.html