Send a query to the machine with *ip* and hopes that the machine will reply back with its name. The implementation of this function is contributed by Jason Anderson. :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can
(self, ip, port = 137, timeout = 30)
| 75 | return d |
| 76 | |
| 77 | def queryIPForName(self, ip, port = 137, timeout = 30): |
| 78 | """ |
| 79 | Send a query to the machine with *ip* and hopes that the machine will reply back with its name. |
| 80 | |
| 81 | The implementation of this function is contributed by Jason Anderson. |
| 82 | |
| 83 | :param string ip: If the NBNSProtocol instance was instianted with broadcast=True, then this parameter can be an empty string. We will leave it to the OS to determine an appropriate broadcast address. |
| 84 | If the NBNSProtocol instance was instianted with broadcast=False, then you should provide a target IP to send the query. |
| 85 | :param integer port: The NetBIOS-NS port (IANA standard defines this port to be 137). You should not touch this parameter unless you know what you are doing. |
| 86 | :param integer/float timeout: Number of seconds to wait for a reply, after which the method will return None |
| 87 | :return: A *twisted.internet.defer.Deferred* instance. The callback function will be called with a list of names of the machine at *ip*. |
| 88 | On timeout, the errback function will be called with a Failure instance wrapping around a NetBIOSTimeout exception |
| 89 | """ |
| 90 | trn_id = random.randint(1, 0xFFFF) |
| 91 | while True: |
| 92 | if trn_id not in self.pending_trns: |
| 93 | break |
| 94 | else: |
| 95 | trn_id = (trn_id + 1) & 0xFFFF |
| 96 | |
| 97 | data = self.prepareNetNameQuery(trn_id) |
| 98 | self.write(data, ip, port) |
| 99 | |
| 100 | d = defer.Deferred() |
| 101 | d2 = defer.Deferred() |
| 102 | d2.addErrback(d.errback) |
| 103 | |
| 104 | def stripCode(ret): |
| 105 | if ret is not None: # got valid response. Somehow the callback is also called when there is an error. |
| 106 | d.callback(map(lambda s: s[0], filter(lambda s: s[1] == TYPE_SERVER, ret))) |
| 107 | |
| 108 | d2.addCallback(stripCode) |
| 109 | self.pending_trns[trn_id] = ( time.time()+timeout, NAME_QUERY, d2 ) |
| 110 | return d |
| 111 | |
| 112 | def stopProtocol(self): |
| 113 | DatagramProtocol.stopProtocol(self) |
nothing calls this directly
no test coverage detected