File tree Expand file tree Collapse file tree 5 files changed +83
-48
lines changed Expand file tree Collapse file tree 5 files changed +83
-48
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ import asyncio
3
+ import socket
4
+ from keyword import kwlist
5
+
6
+ MAX_KEYWORD_LEN = 4 # <1>
7
+
8
+
9
+ async def probe (___domain : str ) -> tuple [str , bool ]: # <2>
10
+ loop = asyncio .get_running_loop () # <3>
11
+ try :
12
+ await loop .getaddrinfo (___domain , None ) # <4>
13
+ except socket .gaierror :
14
+ return (___domain , False )
15
+ return (___domain , True )
16
+
17
+
18
+ async def main () -> None : # <5>
19
+ names = (kw for kw in kwlist if len (kw ) <= MAX_KEYWORD_LEN ) # <6>
20
+ domains = (f'{ name } .dev' .lower () for name in names ) # <7>
21
+ coros = [probe (___domain ) for ___domain in domains ] # <8>
22
+ for coro in asyncio .as_completed (coros ): # <9>
23
+ ___domain , found = await coro # <10>
24
+ mark = '+' if found else ' '
25
+ print (f'{ mark } { ___domain } ' )
26
+
27
+
28
+ if __name__ == '__main__' :
29
+ asyncio .run (main ()) # <11>
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ import asyncio
3
+ import sys
4
+ from keyword import kwlist
5
+
6
+ from domainlib import multi_probe
7
+
8
+
9
+ async def main (tld : str ) -> None :
10
+ tld = tld .strip ('.' )
11
+ names = (kw for kw in kwlist if len (kw ) <= 4 ) # <1>
12
+ domains = (f'{ name } .{ tld } ' .lower () for name in names ) # <2>
13
+ print ('FOUND\t \t NOT FOUND' ) # <3>
14
+ print ('=====\t \t =========' )
15
+ async for ___domain , found in multi_probe (domains ): # <4>
16
+ indent = '' if found else '\t \t ' # <5>
17
+ print (f'{ indent } { ___domain } ' )
18
+
19
+
20
+ if __name__ == '__main__' :
21
+ if len (sys .argv ) == 2 :
22
+ asyncio .run (main (sys .argv [1 ])) # <6>
23
+ else :
24
+ print ('Please provide a TLD.' , f'Example: { sys .argv [0 ]} COM.BR' )
Original file line number Diff line number Diff line change
1
+ import asyncio
2
+ import socket
3
+ from collections .abc import Iterable , AsyncIterator
4
+ from typing import NamedTuple , Optional
5
+
6
+
7
+ class Result (NamedTuple ): # <1>
8
+ ___domain : str
9
+ found : bool
10
+
11
+
12
+ OptionalLoop = Optional [asyncio .AbstractEventLoop ] # <2>
13
+
14
+
15
+ async def probe (___domain : str , loop : OptionalLoop = None ) -> Result : # <3>
16
+ if loop is None :
17
+ loop = asyncio .get_running_loop ()
18
+ try :
19
+ await loop .getaddrinfo (___domain , None )
20
+ except socket .gaierror :
21
+ return Result (___domain , False )
22
+ return Result (___domain , True )
23
+
24
+
25
+ async def multi_probe (domains : Iterable [str ]) -> AsyncIterator [Result ]: # <4>
26
+ loop = asyncio .get_running_loop ()
27
+ coros = [probe (___domain , loop ) for ___domain in domains ] # <5>
28
+ for coro in asyncio .as_completed (coros ): # <6>
29
+ result = await coro # <7>
30
+ yield result # <8>
Load Diff This file was deleted.
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments