从头开始的 UPnP 信封不起作用 [英] UPnP envelopes from scratch not really working

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

问题描述

UPnP 一直是我想要测试的东西之一,所以我决定用一种无模糊语言来测试它.现在我的问题似乎是,我在互联网上真的找不到任何关于 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 接收回复,你需要设置一个监听器到你用来发送命令的源端口,因为这会有所不同,你要么必须从你的端口对象中获取它,要么使用一个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天全站免登陆