forked from nikhilweee/username-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathusername-checker.py
executable file
·86 lines (74 loc) · 2.23 KB
/
username-checker.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
# Tab = 2
import urllib.request as urllib2
import sys
# Define ANSI escape sequences for colored output
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def checkUrl(username, url):
url=url.format(username)
request=urllib2.Request(url)
return parse(request,username)+"\n"
# Process the request and capture the response code
def middleware(request, username):
try:
response=urllib2.urlopen(request)
except urllib2.HTTPError as e:
if e.code==404:
return (e.code, bcolors.OKGREEN, "Available")
else:
return (e.code, bcolors.WARNING, e.reason)
else:
if response.getcode() == 200:
return (response.getcode(), bcolors.FAIL, "Already exists")
# Used for generating colored responses
def parse(request, username):
response = middleware(request, username)
return (bcolors.HEADER+"├─ "+bcolors.ENDC +response[1]+ request.get_full_url()+" ["+str(response[0])+"] "+response[2]+bcolors.ENDC)
def checkUsername(username):
# Read file
try:
with open("URL_CHECK.txt") as f:
l_url=f.readlines()
f.close()
except:
sys.exit("❌ [URL_CHECK.txt] Not found")
# Check the urls
rtn =""
for url in l_url:
# print(url)
rtn+=checkUrl(username, url)
rtn=sorted(rtn.split("\n"))
rtn="\n".join(rtn).strip()
return rtn
def showHeader(username):
rtn =bcolors.HEADER+"__________________________________________________________________\n"+bcolors.ENDC
rtn+=(bcolors.HEADER+"█ "+bcolors.ENDC+bcolors.BOLD+"{}"+bcolors.ENDC+bcolors.HEADER+" █ Checking for availability, please wait...\n"+bcolors.ENDC).format(username)
return rtn
if __name__ == "__main__":
# Ask for a username, instead of an argument
msg=""
if len(sys.argv[1:])==0:
username=input("Username to check: ")
print("This may take a while...")
msg+=showHeader(username)
msg+=checkUsername(username)
else:
# Take username as a system argument
msg="Checking: "
for username in sys.argv[1:]:
msg+=bcolors.BOLD+username+bcolors.ENDC+", "
print(msg[:-2])
print("This may take a while...")
msg=""
for username in sys.argv[1:]:
msg+=showHeader(username)
msg+=checkUsername(username)
## Show
print(msg)