要了解DLNA需要了解upnp,因为DLNA在upnp之上
先把whireshark打开
使用过滤器把网关的包去掉,不然干扰太多,首先说明,只要发包网关一定会发很多包回应,这一步时通过ssdp协议回应的:
分析所有包但是除了网关
udp port 1900 and (!host 192.168.1.1)
//只分析116的包
udp and host 192.168.1.108
首先分析kodi的探测search包
M-SEARCH * HTTP/1.1
MX: 5
ST: upnp:rootdevice
MAN: “ssdp:discover”
User-Agent: UPnP/1.0 DLNADOC/1.50 Kodi
Connection: close
Host: 239.255.255.250:1900
因为我打开着chrome,所以接下去又找到了chrome的包,我们都知道大名鼎鼎的chromecast,也是一样正在往网络上发探测搜索包,kodi 这样的软件也是一样正在网络里面发包。
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: “ssdp:discover”
MX: 1
ST: urn:dial-multiscreen-org:service:dial:1
USER-AGENT: Google Chrome/89.0.4389.90 Windows
在局域网里面有手机开着看电影的时候,无一例外在里面会受到手机不断发送的消息,这样手机会收到设备返回的单播包,手机在里面找到自己的render,显示在界面上,由播放者选择投屏。
这是一个单播回送的信息
HTTP/1.1 200 OK
Location: http://192.168.1.144:1350/DeviceDescription.xml
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
EXT:
BOOTID.UPNP.ORG: 0
CONFIGID.UPNP.ORG: 9678
USN: uuid:97aa0fa5-1810-10f8-edcc-5a1a3e8aa358::upnp:rootdevice
ST: upnp:rootdevice
Date: Wed, 05 May 2021 13:39:43 GMT
协议拥有者也会发送notify信息,表明自己是什么!如以下包
mediarender的信息
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e::upnp:rootdevice
NT: upnp:rootdevice
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e
NT: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e::urn:schemas-upnp-org:device:MediaRenderer:1
NT: urn:schemas-upnp-org:device:MediaRenderer:1
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e::urn:schemas-upnp-org:service:AVTransport:1
NT: urn:schemas-upnp-org:service:AVTransport:1
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e::urn:schemas-upnp-org:service:ConnectionManager:1
NT: urn:schemas-upnp-org:service:ConnectionManager:1
NOTIFY * HTTP/1.1
Host: 239.255.255.250:1900
Location: http://192.168.1.108:1294/
Cache-Control: max-age=1800
Server: UPnP/1.0 DLNADOC/1.50 Kodi
NTS: ssdp:alive
USN: uuid:01820fcf-4611-f824-9f1b-e44c7f0d909e::urn:schemas-upnp-org:service:RenderingControl:1
NT: urn:schemas-upnp-org:service:RenderingControl:1
//以上为ssdp发现协议的过程
下面说到控制和事件
简单对象访问协议(Simple Object Access Protocol:SOAP)定义如何使用XML与HTTP来执行远程过程调用(Remote Procedure Call)。包括控制点如何发送命令消息给设备,设备收到命令消息后如何发送响应消息给控制点。该协议运用在UPnP工作流程的设备控制部分。抓包会发现一堆的soap控制信息。
以下为推送端和kodi的交互过程
GET / HTTP/1.1
Host: 192.168.1.144:1551
User-Agent: Go-http-client/1.1
Accept-Encoding: gzip
HTTP/1.1 200 OK
Date: Wed, 05 May 2021 14:18:51 GMT
Content-Length: 3369
Content-Type: text/xml; charset=“utf-8”
Server: UPnP/1.0 DLNADOC/1.50 Kodi
HTTP/1.1 200 OK
SID: uuid:7b7b6be2-c7db-41e4-c966-0e13962c2f96
TIMEOUT: Second-1800
Date: Wed, 05 May 2021 14:18:51 GMT
Content-Length: 0
Connection: close
Server: UPnP/1.0 DLNADOC/1.50 Kodi
以上的交互过程非常清楚,简单,upnp协议是非常方便的,多分析,多抓包,可以获取很多软件使用的方法。
未完待续,继续补充