![]() ![]() In order to discover such servers modify the browser.py example coming with zeroconf so that it looks for this service (or any other service advertised by the targets of interest) instead of (or in addition to) _http._tcp.local. By default the avahi-deamon advertises the _workstation._tcp.local service. Targets running avahi can be discovered with python zeroconf provided that they advertise some service. Sticking to the letter of the original question, the answer is a qualified yes. From a casual reading of the code and packet monitoring using tcpdump, it seems that (when the registration example is running) zeroconf will respond to address queries but nslookup ignores (or does not receive) the answer. I am also unhappy with the python zeroconf documentation. Or even with multiple queries: dns=(qd=)īut minimal responders may fail to handle dns messages containing multiple queries The dns object could also be created with non-empty query: dns=(qd=) The same result could also be created by: dns=(qd=) An dns object containing an empty query was then created by: dns = (m0) This query was produced by nslookup so its id was non-zero (in this case \xf6\xe8) trying to resolve esp01.local. The empty dns object was created in the above code by passing the constructor a string collected from the network using m0=sock.recvfrom( 1024 ) print '%r'%m0 If len(dns.an)>0 and dns.an.type = _A:print dns._repr_(),dns.an.name,socket.inet_ntoa(dns.an.rdata) If len(dns.qd)>0:print dns._repr_(),dns.qd.name tsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)įor host in : Mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) tsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) Sock = socket.socket( socket.AF_INET, socket.SOCK_DGRAM ) In case of a naive mdns responder which, contrary to the rfc, sends its response via the mdns port, the following code (run on linux and windows and resolving linux avahi, hp printer and esp8266 targets) works for me: (and is also non-compliant as it uses the MDNS port to send the query while it is obviously NOT a full implementation) import socket Interestingly Linux systems running avahi successfully resolve such targets (avahi apparently implementing nf mdns plugin and being a fuller implementation of the mdns protocol) This code works when the target computer runs avahi, but fails when the target runs python zeroconf or the esp8266 mdns implementation. MyRes.nameservers= #mdns multicast addressĪ=myRes.query('7.0.0.10.in-addr.arpa','PTR') In case somebody is still interested in this, the task can be accomplished, on Windows and Linux, using dnspython as follows: import dns.resolver However, on Windows computers not running mDNS software (the default), I get: Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) on win32 Type "help", "copyright", "credits" or "license" for more information. The obvious socket.gethostbyname works on a computer running and configured to use mDNS software (like Avahi): Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) How can I discover the IP address of a computer (or get a list of IP addresses of computers) through mDNS from Python? CLARIFICATION (based on a comment) Or I might have misunderstood completely the mDNS mechanism. (with the obviously dummy port 9, the discard service) of mDNS type PTR that might be the equivalent of a DNS A record. Using tools like avahi-discover, I figured that computers publish records of the service type _workstation._tcp.local. I know of the existence of pyzeroconf, and this is the module I tried to use however, the documentation is scarce and not very helpful to me. ![]() Note: on MS Windows computers that do not run mDNS software, there is no hostname resolution (and obviously ping does not work on said Windows systems). However, I would like to discover the IP address of "server" from a Python application of mine, which runs on both MS Windows and Linux computers. Both "server" and "client" run Avahi, so this is easy. From another Linux computer "client" I can do: ping -c1 server.localĪnd get a reply. ![]() My target is to discover the IP address of a Linux computer "server" in the local network from a Windows computer. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |