iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >python3模拟登录zabbix
  • 156
分享到

python3模拟登录zabbix

zabbix 2023-01-31 08:01:48 156人浏览 薄情痞子

Python 官方文档:入门教程 => 点击学习

摘要

#!/usr/bin/env python # -*- coding: utf-8 -*- import urllib.request import Http.cookiejar import urllib.parse # 登录的主页面

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib.request
import Http.cookiejar
import urllib.parse

# 登录的主页面

hosturl = 'http://xxxxx'  # 自己填写
# post数据接收和处理的页面(我们要向这个页面发送我们构造的Post数据)
posturl = 'http://xxxxxxxxxxxxxxx/index.PHP'  # 从数据包中分析出,处理post请求的url


# 设置一个cookie处理器,它负责从服务器下载cookie到本地,并且在发送请求时带上本地的cookie
cj = http.cookiejar.LWPCookieJar()
cookie_support = urllib.request.HTTPCookieProcessor(cj)
opener = urllib.request.build_opener(cookie_support, urllib.request.HTTPHandler)
urllib.request.install_opener(opener)
# 打开登录主页面(他的目的是从页面下载cookie,这样我们在再送post数据时就有cookie了,否则发送不成功)
h = urllib.request.urlopen(hosturl)


# 构造header,一般header至少要包含一下两项。这两项是从抓到的包里分析得出的。
headers = {'User-Agent': 'Mozilla/5.0 (windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0',
          'Referer': 'http://xxxxxxxxxxxx/index.php'}
            
# 构造Post数据,他也是从抓大的包里分析得出的。
postData = {"name": 'Admin',
             "passWord": 'xxxxxxx',
             "autologin": 1,
             "enter": "Sign in"}
             
             
# 需要给Post数据编码

postData = urllib.parse.urlencode(postData).encode('utf-8')
# 通过urllib2提供的request方法来向指定Url发送我们构造的数据,并完成登录过程
request = urllib.request.Request(posturl, postData, headers)
response = urllib.request.urlopen(request)
text = response.read().decode()
print(text)


--结束END--

本文标题: python3模拟登录zabbix

本文链接: https://www.lsjlt.com/news/192829.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作