frappy-scan: resolve ip numbers to names
Change-Id: I07bf7c274aeb52f2aaa58e8aa2f3bcb2788556ee
This commit is contained in:
parent
b66acd4d73
commit
fdc868c2d7
@ -59,16 +59,23 @@ def decode(msg, addr):
|
||||
|
||||
|
||||
def print_answer(answer, *, short=False):
|
||||
try:
|
||||
hostname = socket.gethostbyaddr(answer.address)[0]
|
||||
address = hostname
|
||||
numeric = f' ({answer.address})'
|
||||
except Exception:
|
||||
address = answer.address
|
||||
numeric = ''
|
||||
if short:
|
||||
# NOTE: keep this easily parseable!
|
||||
print(f'{answer.equipment_id} {answer.address}:{answer.port}')
|
||||
print(f'{answer.equipment_id} {address}:{answer.port}')
|
||||
return
|
||||
print(f'Found {answer.equipment_id} at {answer.address}:')
|
||||
print(f'Found {answer.equipment_id} at {address}{numeric}:')
|
||||
print(f' Port: {answer.port}')
|
||||
print(f' Firmware: {answer.firmware}')
|
||||
desc = answer.description.replace('\n', '\n ')
|
||||
print(f' Node description: {desc}')
|
||||
print()
|
||||
print('-' * 80)
|
||||
|
||||
|
||||
def scan(max_wait=1.0):
|
||||
@ -119,10 +126,14 @@ def listen(*, short=False):
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-l', '--listen', action='store_true',
|
||||
help='Print short info. '
|
||||
'Keep listening after the broadcast.')
|
||||
help='Keep listening after the broadcast.')
|
||||
parser.add_argument('-s', '--short', action='store_true',
|
||||
help='Print short info (always on when listen).')
|
||||
args = parser.parse_args(sys.argv[1:])
|
||||
short = args.listen or args.short
|
||||
if not short:
|
||||
print('-' * 80)
|
||||
for answer in scan():
|
||||
print_answer(answer, short=args.listen)
|
||||
print_answer(answer, short=short)
|
||||
if args.listen:
|
||||
listen(short=args.listen)
|
||||
listen(short=short)
|
||||
|
Loading…
x
Reference in New Issue
Block a user