0

I know nmap has mDNS service discovery script but it wasn't helpful in my case as it doesn't include the correct service names.

So I want to parse the following response as caught in wireshark, any idea on how can I get this response in C or Python program? can I use nmap for this or some special command that I can call via shell/Terminal?

(The one highlighted in blue)

ScreenShot of WireShark

In other words, I am interested in reading the following:

Please Insert Image

4
  • First, what OS are you doing this on? Second, what purpose do you need this for? That is, are you looking for a one-off "network scan" tool, or are you writing a program that uses mDNS? In the latter case, one would usually use a dedicated mDNS library that handles service discovery. Commented Nov 4, 2021 at 7:20
  • Have a look at tcpdump/libpcap to capture network traffic via shell scripts, or via a library (there's also a Python binding, google).
    – dirkt
    Commented Nov 4, 2021 at 7:48
  • Can DIG be helpful here?
    – ALGO
    Commented Nov 4, 2021 at 8:57
  • @user1686 I'm writing a program that uses mDNS, I am wishing to parse the output and not to depend on nmap which does it wrongly.
    – ALGO
    Commented Nov 4, 2021 at 9:02

1 Answer 1

1

If you are writing your own program that uses mDNS – forget Wireshark and forget Nmap. Treat mDNS like any other network protocol that you'd implement, and make your own mDNS queries and receive responses through a standard UDP multicast socket instead of going through "packet captures" and such.

There are two ways to use DNS-SD service discovery via mDNS: either use the existing facilities provided by the OS, or use a library that directly builds queries and parses responses.

  • For example, in Linux, you often have avahi-daemon available as part of the distribution. It takes care of collecting service announcements, so all you need is the "libavahi-client" C library or the "avahi" Python module.

    Similarly, in macOS, you would use one of the "DNS Service Discovery" APIs built in to the system (through mDNSResponder), e.g. old docs. Android and Windows UWP also have mDNS and DNS-SD built-in.

  • If you don't want to rely on external tools, then you'd use something like the "zeroconf" Python module which directly speaks mDNS through sockets.

    I'm not sure which C library is preferred, although mjansson/mdns seems to be okay. The dns-sd GitHub tag has a few more.

  • You could in fact use a standard DNS library (maybe libldns?) for mDNS message parsing, as the mDNS wire protocol is 99% compatible with DNS; the only difference is in two flag definitions. Though if done this way, you'd still need to implement the DNS-SD discovery logic – there's more to it than just "passively wait for responses".

5
  • Hi, Can you include DIG in your answer, I don't want to implement mDNS protocol my main program should parse the response nothing more, someone told me look at DIG but I'm not sure which parameters to provide as the output was too short.
    – ALGO
    Commented Nov 4, 2021 at 13:34
  • 1
    No, I won't be adding that to my answer. In fact, I am very strongly recommending against writing programs that try to parse the output of DIG or any other similar tools whose output is meant for interactive usage. That goes double for mDNS, as DIG is a unicast DNS client but not an mDNS client. Commented Nov 4, 2021 at 13:39
  • Dig output should be similar to the one I showed above, I'm looking for a tool so I can run 1 line and get the same response shown above
    – ALGO
    Commented Nov 4, 2021 at 14:29
  • Can you kindly show an example on how to use zeroconf?
    – ALGO
    Commented Nov 4, 2021 at 14:36
  • Any suggestions, still I don't think this solves my problem
    – ALGO
    Commented Nov 5, 2021 at 13:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .