Simplify subdomain sorting
Replace sorting algorithm with a simplified version. Sort order is not affected by this change.
This commit is contained in:
parent
7850789bb0
commit
80a6458077
35
sublist3r.py
35
sublist3r.py
|
@ -14,7 +14,6 @@ import random
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import threading
|
import threading
|
||||||
import socket
|
import socket
|
||||||
import functools
|
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
# external modules
|
# external modules
|
||||||
|
@ -95,10 +94,10 @@ def write_file(filename, subdomains):
|
||||||
f.write(subdomain + "\r\n")
|
f.write(subdomain + "\r\n")
|
||||||
|
|
||||||
|
|
||||||
def subdomain_cmp(d1, d2):
|
def subdomain_sorting_key(hostname):
|
||||||
"""cmp function for subdomains d1 and d2.
|
"""Sorting key for subdomains
|
||||||
|
|
||||||
This cmp function orders subdomains from the top-level domain at the right
|
This sorting key orders subdomains from the top-level domain at the right
|
||||||
reading left, then moving '^' and 'www' to the top of their group. For
|
reading left, then moving '^' and 'www' to the top of their group. For
|
||||||
example, the following list is sorted correctly:
|
example, the following list is sorted correctly:
|
||||||
|
|
||||||
|
@ -115,24 +114,10 @@ def subdomain_cmp(d1, d2):
|
||||||
]
|
]
|
||||||
|
|
||||||
"""
|
"""
|
||||||
d1 = d1.split('.')[::-1]
|
parts = hostname.split('.')[::-1]
|
||||||
d2 = d2.split('.')[::-1]
|
if parts[-1] == 'www':
|
||||||
|
return parts[:-1], 1
|
||||||
val = 1 if d1 > d2 else (-1 if d1 < d2 else 0)
|
return parts, 0
|
||||||
if ((len(d1) < len(d2)) and
|
|
||||||
(d1[-1] == 'www') and
|
|
||||||
(d1[: - 1] == d2[:len(d1) - 1])):
|
|
||||||
val = -1
|
|
||||||
elif ((len(d1) > len(d2)) and
|
|
||||||
(d2[-1] == 'www') and
|
|
||||||
(d1[:len(d2) - 1] == d2[: - 1])):
|
|
||||||
val = 1
|
|
||||||
elif d1[:-1] == d2[:-1]:
|
|
||||||
if d1[-1] == 'www':
|
|
||||||
val = -1
|
|
||||||
elif d2[-1] == 'www':
|
|
||||||
val = 1
|
|
||||||
return val
|
|
||||||
|
|
||||||
|
|
||||||
class enumratorBase(object):
|
class enumratorBase(object):
|
||||||
|
@ -984,10 +969,8 @@ def main(domain, threads, savefile, ports, silent, verbose, enable_bruteforce, e
|
||||||
subdomains = search_list.union(bruteforce_list)
|
subdomains = search_list.union(bruteforce_list)
|
||||||
|
|
||||||
if subdomains:
|
if subdomains:
|
||||||
subdomains = sorted(
|
subdomains = sorted(subdomains, key=subdomain_sorting_key)
|
||||||
subdomains,
|
|
||||||
key=functools.cmp_to_key(subdomain_cmp),
|
|
||||||
)
|
|
||||||
if savefile:
|
if savefile:
|
||||||
write_file(savefile, subdomains)
|
write_file(savefile, subdomains)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue