从头开始的UPnP信封无法正常工作 [英] UPnP envelopes from scratch not really working

查看:125
本文介绍了从头开始的UPnP信封无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UPnP一直是我要测试的一件事,因此我决定只使用它来进行测试. 现在我的问题似乎是,在Internet上我真的找不到关于UPnP的任何信息,我发现它在UDP上运行并且它使用SOAP信封进行通信,但这就是我能找到的所有信息. 现在,我的目标是我希望能够进行动态端口转发,并可能以后从路由器收集一些信息. 这是到目前为止我一直在测试的代码:

UPnP has always been one of the things I wanted to test out, so I decided to do it an a no fuzz language just to test it out. Now my problem seems to be, that I can't really find any information on the internet regarding UPnP, I have found out that it runs over UDP and that it uses SOAP envelopes to communicate, but that is all the information I can find. Now my goal is that I would like to be able to do dynamic port forwarding and possibly later some information gathering from my router. Here is the code I have been testing on so far:

;;This is the UDP Server
;;Start this first

; Start The UDP Services
;==============================================
UDPStartup()

; Register the cleanup function.
OnAutoItExitRegister("Cleanup")

; Bind to a SOCKET
;==============================================
Local $socket = UDPBind("239.255.255.250", 1900)
If @error <> 0 Then
   MsgBox(0, "UDP Fail", @error, 1)
   Exit;
EndIf;

While 1
    Local $data = UDPRecv($socket, 1024)
    If $data <> "" Then
        MsgBox(0, "UDP DATA", $data, 1)
    EndIf
    Sleep(100)
WEnd

Func Cleanup()
    UDPCloseSocket($socket)
    UDPShutdown()
EndFunc   ;==>Cleanup

出于记录目的,这只是尝试监听UPnP通信. 这只是导致我得到错误代码10049(也称为地址不可用). 所以我问你亲爱的堆高车,我到底是在做错什么?

For the record this is just an attempt to listen in on the UPnP communication. This just results in me getting the error code 10049 also known as address not available. So I am asking you dear stackers, what exactly is it I am doing wrong?

推荐答案

因此,我自己为所有想以此为玩笑的人找到了这个问题的解决方案. UPnP协议的设置显然很挑剔,因此需要密切注意它的设置方式:

So I found the solution to this question myself for anyone that would like to toy around with this. UPnP protocols can apparently be very picky with their setup, so one needs to pay close attention to the way it is set up:

这是发现消息,即使末尾有双行移位,它也必须看起来完全像这样.但是ST消息可以更改,即'ST:ssdp:all'将使其找到所有设备的所有服务,当前的消息确保仅获取rootdevice数据.发现消息通过UDP发送到端口1900上的多播地址239.255.255.250.

This is the discover message, it needs to look exactly like this, even with the double line shift at the end. However the ST message can be changed, i.e. 'ST:ssdp:all' would make it find all services for all devices, the current one makes sure to just get the rootdevice data. The discover message is sent to the multicast address 239.255.255.250 on port 1900 over UDP.

$ strUpnpDiscover ='M-SEARCH * HTTP/1.1'& @CRLF& '主持人: 239.255.255.250:1900'& @CRLF& 'ST:upnp:rootdevice'& @CRLF& 'MAN:"ssdp:discover"'& @CRLF& 'MX:10'& @CRLF& @CRLF

$strUpnpDiscover = 'M-SEARCH * HTTP/1.1' & @CRLF & 'HOST: 239.255.255.250:1900' & @CRLF & 'ST:upnp:rootdevice' & @CRLF & 'MAN:"ssdp:discover"' & @CRLF & 'MX:10' & @CRLF & @CRLF

现在,为了接收来自rootdevice的答复,您需要为用于发送命令的源端口设置一个侦听器,这会有所不同,您要么必须从port对象中获取它,要么使用一个shell命令来获取数据,就像这样(@autoitpid获取程序的父ID):

Now in order to receive the reply from your rootdevice, you need to set up a listener to the source port you used to send the command, as this varies, you will either have to get it from your port object or by using a shell command to get the data, like so(@autoitpid gets the parent id of the program):

$netstat = _getDOSOutput("netstat -aonp udp")
$sourceport = StringReplace(StringMid($netstat, StringInStr($netstat, '*:*' & @AutoItPID)-5, 5), ':' , '')

但是,一旦获得此端口,您要做的就是将UDP侦听器设置为网络接口上找到的端口,您将收到UPnP单元的响应.

But once you get this port, all you have to do is to set up an UDP listener to the found port on your network interface and you will receive the response from you UPnP unit.

现在,一旦收到响应,所有有关如何与设备通信和更改设置的数据都将包含在收到的数据中,寻找

Now once you receive a response, all the data on how to communicate with the device and alter settings will be in the data you receive, look for

LOCATION: http://192.168.1.1:49152/wps_device.xml

此URL将包含您设备的数据表.从这里开始,只是制定适当的SOAP信封,以使设备执行您的淘气出价. :P

this URL will contain the datasheet for your device. From here it is just to formulate a proper SOAP envelope to make the device do your mischievous bidding. :P

有关如何构建SOAP信封的更多信息,请参见此处: http://www. upnp-hacks.org/upnp.html

For more on how to build the SOAP envelopes you can look here: http://www.upnp-hacks.org/upnp.html

我希望这些东西确实对希望构建轻量级UPnP端口转发接口的其他人有所帮助. :)

I hope this stuff really helps anyone else that wants to build a lightweight UPnP port forwarding interface. :)

这篇关于从头开始的UPnP信封无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆