Skip to content

Instantly share code, notes, and snippets.

@milo2012
Last active January 13, 2020 18:11
Show Gist options
  • Save milo2012/889752dadbf2d45c8e96d4a096a1736d to your computer and use it in GitHub Desktop.
Save milo2012/889752dadbf2d45c8e96d4a096a1736d to your computer and use it in GitHub Desktop.
genPunycodeDomain.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import re
import argparse
from ipwhois import IPWhois
from itertools import product
import socket
import signal
import itertools
def dns_timeout(a,b):
raise Exception("DNS timeout")
def getIPHostname(hostname):
signal.signal(signal.SIGALRM, dns_timeout)
signal.alarm(1)
try:
return (socket.gethostbyname(hostname)).strip()
except Exception, exc:
signal.alarm(0)
return None
def replace_str_index(text,index=0,replacement=''):
return '%s%s%s'%(text[:index],replacement,text[index+1:])
def filler(word, from_char, to_char):
#print "here"
resultList=[]
options = [(c,) if c != from_char else (from_char, to_char) for c in word]
for o in product(*options):
results=str(u"".join(o))
resultList.append(results)
return resultList
def filler_list(word_list, from_char, to_char):
return_list=[]
for word in word_list:
return_list=return_list+list(filler(word,from_char,to_char))
return return_list
parser = argparse.ArgumentParser(
prog='PROG',
formatter_class=argparse.RawDescriptionHelpFormatter,
description=('''\
'''))
parser.add_argument("-d", type=str, dest="domain", help="Domain Name")
if len(sys.argv) == 1:
parser.print_help()
sys.exit(1)
args = parser.parse_args()
tmpList=(args.domain).split(".")
tmpDomainSplit=(args.domain).split(".")
topDomainList=[]
tldDomain=''
charList=[]
charList.append(['a','ä|à|á'])
charList.append(['e','ë|è|é'])
charList.append(['i','ï|ì|í'])
charList.append(['o','ö|ò|ó'])
charList.append(['u','ü|ù|ú'])
charList.append(['m','rn'])
charList.append(['s','5'])
charList.append(['b','6'])
charList.append(['g','q|9'])
charList.append(['o','0'])
charList.append(['d','cl'])
charList.append(['w','vv'])
mutateList=[]
tmpResultList=[]
if len(tmpDomainSplit)==2:
for char in charList:
if char[0] in tmpList[0]:
mutateList.append(char)
tldDomain=tmpDomainSplit[1]
wordList=[]
wordList.append(tmpDomainSplit[0])
countMatch=0
for char in charList:
if char[0] in wordList[0]:
countMatch+=1
tmpCount=0
list1=[]
tmpDomainName=wordList[0]
while tmpCount<(countMatch):
if len(tmpResultList)<1:
for char in charList:
if "|" not in char[1]:
list1=list(filler(tmpDomainName, char[0],char[1]))
for x in list1:
x=unicode(x, "utf-8")
if x not in tmpResultList:
tmpResultList.append(x)
ip=getIPHostname(x.encode("idna")+"."+tldDomain)
if ip!=None:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" ["+ip+"]"
else:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" [available]"
else:
tmpUnicodeList=char[1].split("|")
for char1 in tmpUnicodeList:
list2=list(filler(tmpDomainName, char[0],char1))
for x in list2:
x=unicode(x, "utf-8")
if x not in tmpResultList:
tmpResultList.append(x)
ip=getIPHostname(x.encode("idna")+"."+tldDomain)
if ip!=None:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" ["+ip+"]"
else:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" [available]"
else:
for tmpDomainName in tmpResultList:
for char in charList:
if "|" not in char[1]:
list2=list(filler(tmpDomainName, char[0],char[1]))
for x in list2:
x=unicode(x, "utf-8")
if x not in tmpResultList:
tmpResultList.append(x)
ip=getIPHostname(x.encode("idna")+"."+tldDomain)
if ip!=None:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" ["+ip+"]"
else:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" [available]"
else:
tmpUnicodeList=char[1].split("|")
for char1 in tmpUnicodeList:
list2=list(filler(tmpDomainName, char[0],char1))
for x in list2:
x=unicode(x, "utf-8")
if x not in tmpResultList:
tmpResultList.append(x)
ip=getIPHostname(x.encode("idna")+"."+tldDomain)
if ip!=None:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" ["+ip+"]"
else:
print x+"."+tldDomain+"\t"+x.encode("idna")+"."+tldDomain+" [available]"
tmpCount+=1
else:
print "[*] Please enter only the domain name (without the subdomain)."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment