-
Notifications
You must be signed in to change notification settings - Fork 13
/
CatchMail.py
111 lines (89 loc) · 3.13 KB
/
CatchMail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
# @Author: Ph0rse
import time
import sys
import os
import errno
from io import StringIO
from datetime import datetime
import optparse
import json
import traceback
import requests
from pyfiglet import Figlet
__VERSION__ = "0.1"
__TOKEN__ = "0kee.token"
__URL__ = "https://api.0kee.com/api/email/query/"
def haveError(data):
if 'error' in data:
print(">>> Failed!!")
print(">>> "+data['error'])
return True
return False
def showPage():
f = Figlet(font='slant')
print(f.renderText('CatchMail'))
def formatOut(data):
print(">>> Hello "+data["user"])
print(">>> Successful.")
print(">>> Your balance : %d" % data['Balance'])
print(">>> Got %d email:\n" % data['count'])
for email in data['result']:
print(email[0])
def getEmail(token):
# payload = {'domain': options.domain,'limit': options.limit, 'start':options.start, 'token':token}
payload = {'domain': options.domain,'limit': options.limit, 'token':token}
res = requests.post(url=__URL__,data= payload,verify=False)
print(res)
return res.json()
def usage():
s = StringIO()
s.write("Usage: %s <domain> [type] [options]\n" %sys.argv[0])
s.write("\t./python3 CatchMail.py -d 360.cn\n")
s.write("\t./python3 CatchMail.py -d 360.cn -o out.json\n")
s.write("\t./python3 CatchMail.py -d 360.cn -l 100\n")
# s.write("\t./python3 CatchMail.py -d 360.cn -s 100 -l 100\n")
s.seek(0)
return s.read()
def parse_option():
parser = optparse.OptionParser(usage=usage())
parser.add_option("-v", "--version", action="store_true", dest="version")
parser.add_option("-d", "--domain", action="store", type="string", default="null", dest="domain",help="domain of email")
parser.add_option("-l", "--limit", action="store", type="int", default=100, dest="limit",
help="limit number of results. [default: %default]")
parser.add_option("-o", "--outfile", dest="out", type="string", default="null",action="store",
help="output into file")
# parser.add_option("-s", "--start", action="store", type="int", default="0", dest="start")
return parser
def main():
global options, args
parser = parse_option()
options, args = parser.parse_args()
if options.version:
print("CatchMail %s" %__VERSION__)
sys.exit(0)
if (options.domain == "null"):
parser.print_help()
sys.exit(1)
try:
token = open(__TOKEN__,'r').read().strip()
except Exception as e:
sys.stderr.write("%s\n" %e.message)
sys.exit(1)
showPage()
data = getEmail(token)
if options.out != "null":
print(">>> Hello "+data["user"])
print(">>> Successful.")
print(">>> Your balance : %d" % data['Balance'])
print(">>> Got %d email:\n" % data['count'])
print(">>> Imported into "+options.out)
with open(options.out,'w') as outFile:
for emailaddr in data['result']:
outFile.write(emailaddr[0]+'\n')
else:
if haveError(data):
exit()
formatOut(data)
if __name__ == "__main__":
main()