-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathbitsquat.py
45 lines (36 loc) · 1.24 KB
/
bitsquat.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
#!/usr/bin/env python
# contact me: artem [at] dinaburg [dot] org
import sys
import socket
def bitflip(num, pos):
shiftval = 1 << pos
return num ^ shiftval
def is_valid(charnum):
return ((charnum >= ord('0') and charnum <= ord('9')) or
(charnum >= ord('a') and charnum <= ord('z')) or
(charnum >= ord('A') and charnum <= ord('Z')) or
charnum == ord('-'))
def usage():
print "Usage:"
print "bitsquat.py <domain name> <extension>"
print ""
print "example:"
print "bitsquat.py google .com"
print ""
if __name__ == "__main__":
if len(sys.argv) < 2:
usage()
sys.exit()
name = sys.argv[1]
suffix = sys.argv[2]
for i in range(0, len(name)):
val = name[i]
for bit in range(0,8):
newval = bitflip(ord(val), bit)
if is_valid(newval) and val.lower() != chr(newval).lower():
newname = name[:i] + chr(newval) + name[i+1:]
try:
ipaddr = socket.gethostbyname(newname + suffix)
sys.stdout.write('%s%s: is taken (%s)\n' % (newname, suffix, ipaddr,))
except:
sys.stdout.write('%s%s might be available!\n' % (newname, suffix,))