I'm attempting to write a script to connect to a DLNA audio renderer.
There are a few articles on the web giving information on how to do this using UDP
and curl
, however in my particular scenario I'm having some difficulties.
The first step is to send a UDP
multicast announcement over the network to discover DLNA devices on the network.
The message sent to discover devices is:
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MX: 5
Man: "ssdp:discover"
ST: urn:schemas-upnp-org:device:MediaRenderer:1
All lines in this message sent over UDP
should have crlf
line endings and the last line should have an extra crlf
according to this article
That all seems fine. And if the message above is in a file devicediscovery.txt
supposedly it's possible to use netcat
to send out this message:
cat devicediscovery.txt | nc -u -4 239.255.255.250 1900
239.255.255.250:1900
is the multicast address and port over which DLNA
devices communicate.
This all seems fine too, however, as is pointed out in the linked article netcat
ignores the response from the dlna media renderer because there is a mismatch in IP addresses the message is sent out over the dlna multicast address, though the response comes from the router. The article suggests using tcpdump
to capture the response, however I'm on Windows and using Bash on Windows WSL
so tcpdump is not available and such a technique would possibly be complicated when developing a script to automate the dlna connection.
Would it be possible to use two seperate instances of netcat
? One instance sending the message over the dlna multicast address and the other listening for the response from the router?
I have tried to get this working, however I'm unsure which port netcat
should be listening on to hear the incomming response. Is there a standard port that netcat
should listen on?
I've tried commands such as: nc -luv 192.168.0.1
, however I get an error Servname not supported for ai_socktype
. I've tried to remedy this by playing around with /etc/services
but had no luck.
What command can I use and how must I configure the system to listen for the response from the search for dlna devices? I'd like to parse the response in a script so that the dlna connection can be automated.
Although you mention issues with DLNA it looks that you are really asking for how to best troubleshoot this.
Network cards don't allow access to incoming traffic unless set in promiscuous mode. Netcat won't be able to do what you need because of this. But, you can use Wireshark to read the traffic on the interface. TCPdump and Wireshark have close ties and almost interchangeable.
I would recommend to use it to troubleshoot further. Ppost the capture (not just a picture) and show where it failed.