def print_reply(self, opts, buf, rtt): ns = netbios.NS(buf) d = {} for rr in ns.an: for name, svc, flags in rr.nodenames: unique = (flags & netbios.NS_NAME_G == 0) if svc == 0 and unique and 'host' not in d: d['host'] = name elif svc == 0x03 and unique: if 'user' not in d or d['user'].startswith(d['host']): d['user'] = name print('%d bytes from %s: id=%d time=%.3f ms host=%s user=%s' % (len(buf), opts.ip, ns.id, rtt * 1000, d.get( 'host', ''), d.get('user', '')))
def gen_ping(self, opts): for i in range(opts.count): ns = netbios.NS( id=i, qd=[netbios.NS.Q(type=netbios.NS_NBSTAT, name='*')]) yield str(ns)