Created
June 19, 2017 14:27
-
-
Save m-lh/bdc6c7b7d0af8f1982f399053f1b4d83 to your computer and use it in GitHub Desktop.
瞎写系列::从注册的地方看到底哪个账户注册了
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import string | |
| from itertools import product | |
| url = 'https://github.com/signup_check/username' | |
| data = b'value=m-mmm&authenticity_token=UEibfyLaqA5qO%2BH5ISLFc4HsVbS3JMtllC3UWvu3aB4nSrsPFoFhcrpS8wW1yKaxw1nl7eaKD2XFKhlE%2BQv%2BHQ%3D%3D' | |
| header = {'Accept': '*/*', | |
| 'Accept-Language': 'zh-CN', | |
| 'Cache-Control': 'no-cache', | |
| 'Connection': 'Keep-Alive', | |
| 'Content-Type': 'application/x-www-form-urlencoded', | |
| 'Cookie': '_gh_sess=eyJzZXNzaW9uX2lkIjoiZWIyY2Y3N2JlZGViNTZlODNhNGE2YjE3N2M3M2UwMjUiLCJfY3NyZl90b2tlbiI6IllxUzk1SjZKcGMrcmwvRDRLQitGUVpudUpzOWhDbW9vcW1vRnN0NU91QjA9IiwicmVmZXJyYWxfY29kZSI6Imh0dHBzOi8vZ2l0aHViLmNvbS8iLCJsYXN0X3dyaXRlIjoxNDk0MzIzNTQwMzI5fQ%3D%3D--229858bbaee1ca7cb31bb59381b873fd1cccd21d; ' | |
| 'tz=Asia%2FShanghai; logged_in=no; ' | |
| '_octo=GH1.1.1980393681.1451802706; ' | |
| '_ga=GA1.2.2121475954.1451802707; ' | |
| '__utma=58162108.2121475954.1451802707.1468071434.1468071434.1', | |
| 'Host': 'github.com', | |
| 'Referer': 'https://github.com/join', | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', | |
| 'x-requested-with': 'XMLHttpRequest', | |
| } | |
| s = requests.session() | |
| def str_req2dict(ss): | |
| """从ie的请求标头中全部拷贝出来的,转化为字典""" | |
| ss=ss.splitlines()[1:] | |
| sss=[k.strip().split('\t') for k in ss] | |
| r={k:v for k,v in sss} | |
| from pprint import pprint | |
| pprint(r) | |
| def check_name(name): | |
| d = b'value='+name.encode()+b'&authenticity_token=UEibfyLaqA5qO%2BH5ISLFc4HsVbS3JMtllC3UWvu3aB4nSrsPFoFhcrpS8wW1yKaxw1nl7eaKD2XFKhlE%2BQv%2BHQ%3D%3D' | |
| h = {'Accept': '*/*', | |
| 'Accept-Language': 'zh-CN', | |
| 'Cache-Control': 'no-cache', | |
| 'Connection': 'Keep-Alive', | |
| 'Content-Type': 'application/x-www-form-urlencoded', | |
| 'Host': 'github.com', | |
| 'Referer': 'https://github.com/join', | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Trident/7.0; rv:11.0) like Gecko', | |
| 'x-requested-with': 'XMLHttpRequest', | |
| } | |
| r = s.post(url,data=d,headers=h,timeout=5) | |
| return r | |
| def generate_names(length=1): | |
| letters = string.ascii_lowercase+'-' | |
| n=product(letters, repeat=length) | |
| for res in n: | |
| name=''.join(res) | |
| if name.startswith('-') or name.endswith('-') or name.count('-')>1: | |
| continue | |
| yield name | |
| def init(): | |
| for i in range(3): | |
| try: | |
| r=s.post(url,data=data,headers=header,timeout=10) | |
| if r.ok: | |
| return r | |
| except requests.exceptions.ReadTimeout: | |
| pass | |
| return r | |
| def check_names(length): | |
| for name in generate_names(length): | |
| res=check_name(name) | |
| print('[#]',name,res.text) | |
| if __name__=='__main__': | |
| r = init() | |
| pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment