获取QQ企业邮箱通讯录PY脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Last Modified time: 2016-03-03 22:45:18
# @Description: 获取腾讯企业邮箱通讯录
import requests
import re
import rsa
import sys
import base64
import time
import argparse
reload(sys) sys.setdefaultencoding('utf8') # 打印部门人员信息
def print_tree(id, department_infos, level, staff_infors, f):
prefix = '----' * level
text = prefix + department_infos[id]['name'] + prefix
print text
f.write(text + '\n')
for key, value in department_infos.items():
if value['pid'] == id:
print_tree(
value['id'], department_infos, level + 1, staff_infors, f)
prefix = ' ' * level
for staff in staff_infors:
if staff['pid'] == id:
text = prefix + staff['name'] + ' ' + staff['alias']
print text
f.write(text + '\n') # 提取RSA算法的公钥
def get_public_key(content):
regexp = r'var\s*PublicKey\s*=\s*"(\w+?)";'
results = re.findall(regexp, content)
if results:
return results[0] # 获取ts参数
def get_ts(content):
regexp = r'PublicTs\s*=\s*"([0-9]+)"'
results = re.findall(regexp, content)
if results:
return results[0] # 计算p参数
def get_p(public_key, password, ts):
public_key = rsa.PublicKey(int(public_key, 16), 65537)
res_tmp = rsa.encrypt(
'{password}\n{ts}\n'.format(password=password, ts=ts), public_key)
return base64.b64encode(res_tmp) def msg():
return 'python get_tencent_exmail_contacts.py -u name@domain.com -p passw0rd' if __name__ == "__main__":
description = "获取腾讯企业邮箱通讯录"
parser = argparse.ArgumentParser(description=description, usage=msg())
parser.add_argument(
"-u", "--email", required=True, dest="email", help="邮箱名")
parser.add_argument(
"-p", "--password", required=True, dest="password", help="邮箱密码")
parser.add_argument(
"-l", "--limit", required=False, dest="limit", default=10000, help="通讯录条数")
parser.add_argument(
"-e", "--efile", required=False, dest="emailfile", default="emails.txt", help="邮箱保存文件")
parser.add_argument(
"-d", "--dfile", required=False, dest="departfile", default="departments.txt", help="部门信息保存文件")
args = parser.parse_args()
email = args.email
password = args.password
limit = args.limit
emailfile = args.emailfile
departfile = args.departfile
session = requests.Session() headers = {'Connection': 'keep-alive',
'Cache-Control': 'max-age=0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Upgrade-Insecure-Requests': 1,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36',
'DNT': 1,
'Accept-Encoding': 'gzip, deflate, sdch',
'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4',
}
resp = session.get('http://exmail.qq.com/login', headers=headers)
content = resp.content public_key = get_public_key(content) ts = get_ts(content) p = get_p(public_key, password, ts) # print ts
# print public_key
# print p uin = email.split('@')[0]
domain = email.split('@')[1]
# print uin
# print domain post_data = {}
post_data['sid'] = ''
post_data['firstlogin'] = False
post_data['domain'] = domain
post_data['aliastype'] = 'other'
post_data['errtemplate'] = 'dm_loginpage'
post_data['first_step'] = ''
post_data['buy_amount'] = ''
post_data['year'] = ''
post_data['company_name'] = ''
post_data['is_get_dp_coupon'] = ''
post_data['starttime'] = int(time.time() * 1000)
post_data['redirecturl'] = ''
post_data['f'] = 'biz'
post_data['uin'] = uin
post_data['p'] = p
post_data['delegate_url'] = ''
post_data['ts'] = ts
post_data['from'] = ''
post_data['ppp'] = ''
post_data['chg'] = 0
post_data['loginentry'] = 3
post_data['s'] = ''
post_data['dmtype'] = 'bizmail'
post_data['fun'] = ''
post_data['inputuin'] = email
post_data['verifycode'] = '' headers = {'Content-Type': 'application/x-www-form-urlencoded'}
url = 'https://exmail.qq.com/cgi-bin/login'
resp = session.post(url, headers=headers, data=post_data) regexp = r'sid=(.*?)"' sid = re.findall(regexp, resp.content)[0]
url = 'http://exmail.qq.com/cgi-bin/laddr_biz?action=show_party_list&sid={sid}&t=contact&view=biz'
resp = session.get(url.format(sid=sid)) text = resp.text
regexp = r'{id:"(\S*?)", pid:"(\S*?)", name:"(\S*?)", order:"(\S*?)"}'
results = re.findall(regexp, text)
department_ids = []
department_infor = dict()
root_department = None
for item in results:
department_ids.append(item[0])
department = dict(id=item[0], pid=item[1], name=item[2], order=item[3])
department_infor[item[0]] = department
if item[1] == 0 or item[1] == '':
root_department = department regexp = r'{uin:"(\S*?)",pid:"(\S*?)",name:"(\S*?)",alias:"(\S*?)",sex:"(\S*?)",pos:"(\S*?)",tel:"(\S*?)",birth:"(\S*?)",slave_alias:"(\S*?)",department:"(\S*?)",mobile:"(\S*?)"}' all_emails = []
staff_infors = []
for department_id in department_ids:
url = 'http://exmail.qq.com/cgi-bin/laddr_biz?t=memtree&limit={limit}&partyid={partyid}&action=show_party&sid={sid}'
resp = session.get(
url.format(limit=limit, sid=sid, partyid=department_id))
text = resp.text
results = re.findall(regexp, text) for item in results:
all_emails.append(item[3])
print item[3]
staff = dict(uin=item[0], pid=item[1], name=item[2], alias=item[3], sex=item[4], pos=item[
5], tel=item[6], birth=item[7], slave_alias=item[8], department=item[9], mobile=item[10])
staff_infors.append(staff) with open(emailfile, 'w') as f:
for item in all_emails:
f.write(item + '\n') with open(departfile, 'w') as f:
print_tree(root_department['id'], department_infor, 0, staff_infors, f) print("total email count: %i" % len(all_emails))
print("total department count: %i" % len(department_ids))
获取QQ企业邮箱通讯录PY脚本的更多相关文章
- django使用QQ企业邮箱发送邮件
一.首先申请QQ企业邮箱 免费QQ企业邮箱地址如下:https://exmail.qq.com/signupfree?refer=intro#signup/free 二.配置自己的域名 在域名解析中添 ...
- 腾讯QQ企业邮箱在ruby on rails 框架中的mailer配置
在编写ruby on rails程序时,我们可能会需要用到发送邮件的程序,如果使用gmail进行smtp发送一般问题不大,但很多企业使用的是腾讯QQ企业邮箱.使用该邮箱进行链接时出现各种错误,goog ...
- Gitlab使用QQ企业邮箱发送邮件
注册QQ企业邮箱 地址 https://exmail.qq.com/signupfree?refer=intro#signup/free 注册完成后解析 编辑/etc/gitlab/gitlab.rb ...
- Python qq企业邮箱发送邮件
Python qq企业邮箱发送邮件 进入客户端设置: 下面是代码部分: from email.header import Header from email.mime.text import MIME ...
- 配置QQ企业邮箱小结
https://exmail.qq.com/login 1,注册管理员账号 2,添加域名 3.设置MX记录 记录类型选:MX记录 主机记录(RR):不填(非万网可以填写@) 记录值与MX优先级分别为: ...
- 腾讯QQ企业邮箱POP3/SMTP设置
腾讯企业邮箱支持通过client进行邮件管理. POP3/SMTP协议 收发邮件server地址分别例如以下. 接收邮件server:pop.exmail.qq.com (port 110) 发送邮件 ...
- QQ企业邮箱+Spring+Javamail+ActiveMQ(发送企业邮件)
原来有个教程是关于Javamail的,但是那个是自己写Javamail的发送过程,这次不同的是:使用Spring的Mail功能,使用了消息队列. 先看一下设想的场景 不过本文重点不是消息队列,而是使用 ...
- panabit允许一台代理服务器只能收QQ企业邮箱,和内网ip通讯,限制除了QQ企业邮箱以外的所有内容规则
环境: 可访公网网的内网网段:192.168.0.0/24(员工网段) 192.168.2.0/24(服务器网段)两个内网网段. 不能访问公网的内网网段:192.168.4.0/24 4网段利用fo ...
- C# 发送邮件,QQ企业邮箱测试成功
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...
随机推荐
- Linq to Entities下存储过程的使用方法
1.首先在数据库中创建好存储过程. 2.在实体模型中添加存储过程的映射.此时根据映射过来的查询结果有两种途径:第一种可以选择添加选择的存储过程的函数到实体模型中.这样的话,查询的结果将会是xxx_re ...
- java修改request的paramMap
最近做项目,发现要修改request的参数内容.因为想要在request的paramMap里面默认注入,modifier和modifierName,这些内容.但是这个Map是不能修改的.所以采用了如下 ...
- Java Web页面跳转
Java Web的页面跳转分服务器跳转和客户端跳转: 服务器端跳转 的特点是:跳转之后浏览器的地址栏不会发生任何变化,在使用rquest属性范围时,能将request属性保存到跳转页.执行到跳转语句 ...
- matplotlib安装问题
1, 安装matplotlib 官网直接下载:http://matplotlib.sourceforge.net/ 我找了一个.exe的安装完毕之后, 直接 import matplotlib, no ...
- c#面向对象基础 类、方法、方法重载
C#是纯粹的面向对象编程语言,它真正体现了“一切皆为对象”的精神.在C#中,即使是最基本的数据类型,如int,double,bool类型,都属于System.Object(Object为所有类型的基类 ...
- SpringMVC详细示例实战教程
一.SpringMVC基础入门,创建一个HelloWorld程序 1.首先,导入SpringMVC需要的jar包. 2.添加Web.xml配置文件中关于SpringMVC的配置 1 2 3 4 5 6 ...
- 形形色色的下拉菜单 (css3)
http://www.iteye.com/news/25339
- Wb应用程序开放原理
简介:基于wb的浏览器/服务器(简称B/S),架构编程,已经成为目前企业级应用程序开发的主流. 1.企业应用计算的演变:主机/呀终端的集中 ...
- Flink - metrics
Metrics是以MetricsGroup来组织的 MetricGroup MetricGroup 这就是个metric容器,里面可以放subGroup,或者各种metric 所以主要的接口就是注 ...
- ArcGIS Server,4000端口被占用
server使用的端口:http://resources.arcgis.com/zh-cn/help/main/10.2/index.html#//015400000537000000 cmd 输入命 ...