/usr/share/doc/python-dpkt/examples/nbtping.py is in python-dpkt 1.8.r98-0.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #!/usr/bin/env python
import socket
from dpkt import netbios
import ping
class NBTPing(ping.Ping):
def __init__(self):
ping.Ping.__init__(self)
self.op.add_option('-p', dest='port', type='int', default=137,
help='Remote NetBIOS name server port')
def open_sock(self, opts):
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect((opts.ip, opts.port))
sock.settimeout(opts.wait)
return sock
def gen_ping(self, opts):
for i in xrange(opts.count):
ns = netbios.NS(id=i,
qd=[ netbios.NS.Q(type=netbios.NS_NBSTAT, name='*') ])
yield str(ns)
def print_header(self, opts):
print 'NBTPING %s:' % opts.ip
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', ''))
if __name__ == '__main__':
NBTPing().main()
|