-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEscaneo.py
47 lines (38 loc) · 1.34 KB
/
Escaneo.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
44
45
46
47
import asyncio
import click
import sys
from bleak import BleakScanner
#Constantes
MAX_INTERATIONS = 100
TIPO = "name"
@click.group()
def main():
pass
@main.command()
@click.argument("filter", required=True, type=str)
@click.option("--type", "-t", default=TIPO, type=str, help="Search Type: name|mac")
@click.option("--iter", "-i", default=MAX_INTERATIONS, type=int, help="Iteration quantity. Default 100.")
def scan(filter: str, type:str,iter:int):
asyncio.run(runScanLE(filter,type,iter))
async def runScanLE(target: str, type:str,iter:int):
n=iter
async with BleakScanner() as scanner:
print(f"Buscando la cadena \"{target}\" en un máximo de {n} iteraciones")
async for bd, ad in scanner.advertisement_data():
found = False
if type == "name":
found = target.lower() in bd.name.lower()
elif type == "mac":
found = target.lower() in bd.address.lower()
else:
found = target.lower() in bd.name.lower()
if found:
print(f"{n} - Lo encontré: {bd.name} - {bd.address} || {ad!r}")
break
else:
print(f"{n} - {bd.name} - {bd.address}")
n -= 1
if n == 0:
break
if __name__ == "__main__":
main()