upnp以及ssdp服务

linux发现SSDP服务的命令
sudo apt-get install gupnp-tools
gssdp-discover -i wlan0 --timeout=3

windowns发现SSDP服务的命令
使用python命令来发送udp的组播包,参考
https://blog.cloudflare.com/ssdp-100gbps/

参考代码:
#!/usr/bin/env python2
import socket
import sys
import time

dst = "239.255.255.250"
if len(sys.argv) > 1:
    dst = sys.argv[1]
st = "upnp:rootdevice"
if len(sys.argv) > 2:
    st = sys.argv[2]

msg = [
    'M-SEARCH * HTTP/1.1',
    'Host:239.255.255.250:1900',
    'ST:%s' % (st,),
    'Man:"ssdp:discover"',
    'MX:1',
    '']

##msg = [
##    'CACHE-CONTROL: max-age=66',
##    'LOCATION: http://192.168.2.7:49152/description.xml',
##    'OPT: "http://schemas.upnp.org/upnp/1/0/"; ns=01',
##    '01-NLS: 1c23906c-1dd2-1I wi1b2-bafb-bcb5c20b5861',
##    'NT: urn:schemas-upnp-org:service:ConnectionManager:1',
##    'NTS: ssdp:alive',
##    'SERVER: Linux/4.9.113 HTTP/1.0',
##    'X-User-Agent: redsonic',
##    'USN: uuid:29bca68c-dad4-1a0e-3773-ca2c132a272b::urn:schemas-upnp-org:service:ConnectionManager:1',
##    '']
##    

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
s.settimeout(10)

for i in range(1,10000):
    s.sendto(('\r\n'.join(msg)).encode(), (dst, 1900) )
    time.sleep(0.01)

data, addr = s.recvfrom(32*1024)

python脚本使用方法:
python IDLE:
1 file-open 上面的py文件
2 F5运行文件

设备端会收到相应的SSDP组播包

I wifihelp 714960/0x1420cc08 tcpip_filter_packet:826] ignore packet 192.168.1.183 => 239.255.255.250@1900

[715459][IP: v:0x4 hlen:20 tos:0xI0 tlen:123 id:0xe122 offset:0 ttl:1 protocl:17/UDP cksum:0x37e4]
[715499][ETH-S][IP-17]192.168.1.183:57307->239.255.255.250:1900, len:137, msg:M-SEARCH * HTTP/1.1
Host:239.255.255.250:1900
ST:upnp:rootdevice
Man:"ssdp:discover"
MX:1
参考
https://zhuanlan.zhihu.com/p/40407669

If you are experiencing problems with the Universal Plug and Play service, your computer might not be able to automatically detect the presence of other networked devices, such as PCs, printers, Internet access points and so on. That is where the UPnP Test application comes in. This simple program is designed to help you identify the issues that prevent the UPnP protocol from functioning correctly. Before you get your hopes up, you should know that this tool does not solve the detected problems, but only performs a series of tests to identify the possible causes. One advantage is that the application does not require installation, so your system registry is not affected in any way. The interface is compact and simple, comprising only two panels: one that displays the test type and its short description and the other for viewing which of the tests passed and which failed. The program can verify whether the operating system provides support for the UPnP service and allows you to check if the Simple Service Discovery Protocol (SSDP) and the UPnPHost services are running. It also verifies the connection between your network adapter and your router and the system's capacity to receive UPnP messages, as well as the router's capability to report an external IP address. One of the tests is designed to check if the Windows firewall service is blocking the traffic between your router and the system, thus preventing UPnP from working. The results can be copied to your clipboard by simply pressing a button and the tests can be redone easily. If you want to fix the detected issues, the link in the main interface can prove useful. In conclusion, UPnP Test is a simple tool for detecting problems related to device-to-device networking. However, it can only suggest possible reasons why the UPnP is not working, fixing the detected issues is totally up to you.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值