5

I'm trying to find out the IP address of an UPnP device connected to my network. On Windows I'm able to get this information by referring to the following question on StackOverflow:

UPnP Multicast: missing answers from M-SEARCH (Discovery)

However, how can I do on Linux?

Community
  • 1
  • 1
ChristianR
  • 133
  • 2
  • 7
  • How do you want to implement the solution (shell script, C++, Java)? – trojanfoe Jul 02 '13 at 10:20
  • 1
    What do you know about this device? Can you access the router? Is the IP address dynamically established ( using DHCP) or fixed? Do you expect to be on the same subnet with your Linux box? – Floris Jul 02 '13 at 10:23
  • Im sorry, i want to implement it in shell script. The device gets its ip from a DHCP. – ChristianR Jul 02 '13 at 10:39
  • Assuming you have many devices on your subnet, how will you recognize "the right one"? Does it respond to particular commands? Send out data packets? .... – Floris Jul 02 '13 at 10:44
  • In the response of the m-search request of the mentioned link i get a ST tag with a specific "ST:urn:schemas-..." format. – ChristianR Jul 02 '13 at 10:51
  • Your link is to a C# program using socket communication. I don't think you can reasonably be able to expect to do the same as it does from a shell script. You need to port the program to linux (perhaps you can use Mono to run it without changes; I'm not sure). – davmac Jul 02 '13 at 12:24
  • @davmac has a point - but see [this tutorial](http://www.troubleshooters.com/codecorn/sockets/) for a way to do basic socket programming from the shell. Not for the faint of heart, but could be done. Note the example shows both server and client - you ought to need only the "client" part of the communication, assuming the uPnP device is the "server". Since I don't have anything like your setup, it would be very hard to show you how to do this. However, if you follow the tutorial and get "almost there", post your results and we'll try to help debug. – Floris Jul 02 '13 at 12:47

1 Answers1

6

Depending on how you identify the correct device you could take a look at gssdp-discover in gupnp-tools package (which is part of the GUPnP project). If that is not what you want but you are prepared to code a bit, take a look at the source: gssdp-discover is only ~100 lines of C so you should be a able to do what you want in a few dozen lines of python...

Example:

$ gssdp-discover -t uuid:c013f58f-3072-4c3b-9df8-4f869c03edf2 -n 3
Using network interface wlan0
Scanning for resources matching uuid:c013f58f-3072-4c3b-9df8-4f869c03edf2
resource available
  USN:      uuid:c013f58f-3072-4c3b-9df8-4f869c03edf2
  Location: http://10.10.15.61:49152/description.xml
$ 
Jussi Kukkonen
  • 13,857
  • 1
  • 37
  • 54