File tree Expand file tree Collapse file tree 7 files changed +80
-0
lines changed Expand file tree Collapse file tree 7 files changed +80
-0
lines changed File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ from curio import run , TaskGroup
3
+ from curio .socket import getaddrinfo , gaierror
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
+ try :
11
+ await getaddrinfo (___domain , None ) # <4>
12
+ except gaierror :
13
+ return (___domain , False )
14
+ return (___domain , True )
15
+
16
+
17
+ async def main () -> None : # <5>
18
+ names = (kw for kw in kwlist if len (kw ) <= MAX_KEYWORD_LEN ) # <6>
19
+ domains = (f'{ name } .dev' .lower () for name in names ) # <7>
20
+ async with TaskGroup () as group :
21
+ for ___domain in domains :
22
+ await group .spawn (probe , ___domain )
23
+ async for task in group : # <9>
24
+ ___domain , found = task .result # <10>
25
+ mark = '+' if found else ' '
26
+ print (f'{ mark } { ___domain } ' )
27
+
28
+
29
+ if __name__ == '__main__' :
30
+ run (main ()) # <11>
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+ import curio
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 )
12
+ domains = (f'{ name } .{ tld } ' .lower () for name in names )
13
+ print ('FOUND\t \t NOT FOUND' )
14
+ print ('=====\t \t =========' )
15
+ async for ___domain , found in multi_probe (domains ):
16
+ indent = '' if found else '\t \t '
17
+ print (f'{ indent } { ___domain } ' )
18
+
19
+
20
+ if __name__ == '__main__' :
21
+ if len (sys .argv ) == 2 :
22
+ curio .run (main (sys .argv [1 ]))
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
+ from curio import TaskGroup
2
+ from curio .socket import getaddrinfo , gaierror
3
+ from collections .abc import Iterable , AsyncIterator
4
+ from typing import NamedTuple
5
+
6
+
7
+ class Result (NamedTuple ):
8
+ ___domain : str
9
+ found : bool
10
+
11
+
12
+ async def probe (___domain : str ) -> Result :
13
+ try :
14
+ await getaddrinfo (___domain , None )
15
+ except gaierror :
16
+ return Result (___domain , False )
17
+ return Result (___domain , True )
18
+
19
+
20
+ async def multi_probe (domains : Iterable [str ]) -> AsyncIterator [Result ]:
21
+ async with TaskGroup () as group :
22
+ for ___domain in domains :
23
+ await group .spawn (probe , ___domain )
24
+ async for task in group :
25
+ yield task .result
Original file line number Diff line number Diff line change
1
+ curio == 1.5
You can’t perform that action at this time.
0 commit comments