MikeWang000000 / Natter

Expose your TCP/UDP port behind full-cone NAT to the Internet.
GNU General Public License v3.0
1.3k stars 107 forks source link

uPnP无法使用 #96

Open Papklp1 opened 2 weeks ago

Papklp1 commented 2 weeks ago

光猫侧已开启upnp,没有二级路由 Python 3.12.3 Natter 2.1.1 执行sudo natter.py -v -m iptables -p 55555 -U

2024-06-08 09:15:13 [I] Natter v2.1.1
2024-06-08 09:15:13 [D] fwd-iptables: Found iptables (1, 8, 10)
2024-06-08 09:15:13 [D] fwd-iptables: Cleaning up Natter rules
2024-06-08 09:15:14 [D] stun: Got address tcp://111.111.111.111:6452 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:35413
2024-06-08 09:15:14 [D] keep-alive: Connected to host tcp://www.baidu.com:80
2024-06-08 09:15:17 [D] keep-alive: OK
2024-06-08 09:15:17 [D] stun: Got address tcp://111.111.111.111:6452 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:35413
2024-06-08 09:15:17 [D] fwd-iptables: Adding rule tcp://192.168.1.31:35413 forward to tcp://192.168.1.31:55555
2024-06-08 09:15:17 [I] 
2024-06-08 09:15:17 [I] Scanning UPnP Devices...
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:17 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-08 09:15:18 [E] upnp: failed to load service from http://192.168.1.3:37443/upnpap.xml: Invalid response from HTTP server
Traceback (most recent call last):
  File "/usr/bin/natter.py", line 1849, in <module>
    main()
  File "/usr/bin/natter.py", line 1840, in main
    natter_main(show_title)
  File "/usr/bin/natter.py", line 1730, in natter_main
    upnp_router = upnp.discover_router()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/natter.py", line 1220, in discover_router
    devs = self._discover()
           ^^^^^^^^^^^^^^^^
  File "/usr/bin/natter.py", line 1285, in _discover
    d._load_services()
  File "/usr/bin/natter.py", line 1132, in _load_services
    services_d.update(sd)
TypeError: 'NoneType' object is not iterable
2024-06-08 09:15:18 [D] fwd-iptables: Cleaning up Natter rules
Droid-MAX commented 2 weeks ago

换个角度想,有没有可能是光猫的UPnP组件的问题?

Papklp1 commented 2 weeks ago

应该不能吧 图片

MikeWang000000 commented 2 weeks ago

这种情况比较少见,像是光猫没有返回标准的 HTTP 响应。

https://github.com/MikeWang000000/Natter/blob/f8257e8cff8f013202d9af9d0f9af4d986c1c718/natter.py#L1164 将 1164 行 sock.close() 临时改成 sock.close(); print(response)

然后发一下输出的内容呢?IP 地址等敏感信息可以隐去。

Papklp1 commented 2 weeks ago
╰─ sudo ./natter.py -v -m iptables -p 55555 -U
2024-06-10 19:05:46 [I] Natter v2.1.1
2024-06-10 19:05:46 [D] fwd-iptables: Found iptables (1, 8, 10)
2024-06-10 19:05:46 [D] fwd-iptables: Cleaning up Natter rules
2024-06-10 19:05:46 [D] stun: Got address tcp://111.111.111.111:6600 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:33817
2024-06-10 19:05:46 [D] keep-alive: Connected to host tcp://www.baidu.com:80
2024-06-10 19:05:49 [D] keep-alive: OK
2024-06-10 19:05:50 [D] stun: Got address tcp://111.111.111.111:6600 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:33817
2024-06-10 19:05:50 [D] fwd-iptables: Adding rule tcp://192.168.1.31:33817 forward to tcp://192.168.1.31:55555
2024-06-10 19:05:50 [I] 
2024-06-10 19:05:50 [I] Scanning UPnP Devices...
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.3:37443/upnpap.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-10 19:05:50 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
b''
2024-06-10 19:05:51 [E] upnp: failed to load service from http://192.168.1.3:37443/upnpap.xml: Invalid response from HTTP server
Traceback (most recent call last):
  File "/home/papklp/Natter/./natter.py", line 1849, in <module>
    main()
  File "/home/papklp/Natter/./natter.py", line 1840, in main
    natter_main(show_title)
  File "/home/papklp/Natter/./natter.py", line 1730, in natter_main
    upnp_router = upnp.discover_router()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/papklp/Natter/./natter.py", line 1220, in discover_router
    devs = self._discover()
           ^^^^^^^^^^^^^^^^
  File "/home/papklp/Natter/./natter.py", line 1285, in _discover
    d._load_services()
  File "/home/papklp/Natter/./natter.py", line 1132, in _load_services
    services_d.update(sd)
TypeError: 'NoneType' object is not iterable
2024-06-10 19:05:51 [D] fwd-iptables: Cleaning up Natter rules

似乎是同样的报错

Droid-MAX commented 2 weeks ago

别用光猫

Papklp1 commented 2 weeks ago

又试了一下gopeed和qbittorrent,都可以正常upnp

MikeWang000000 commented 2 weeks ago

手动捂脸,http://192.168.1.3:37443/upnpap.xml 光猫响应的这个地址是不是打不开? 然后再试试 http://192.168.1.1:49652/49652gatedesc.xml

MikeWang000000 commented 2 weeks ago

别用光猫

也不能说别用光猫,光猫的内置功能可能比较粗糙,我们对一些不正常的现象做一些容错处理,也是能用的。

Papklp1 commented 2 weeks ago

192.168.1.1的可以打开,192.168.1.3的不行

Droid-MAX commented 2 weeks ago

怪了,有两个upnp网关?

Papklp1 commented 2 weeks ago

1.3是从光猫

Droid-MAX commented 2 weeks ago

那就是局域网内有多个upnp网关设备?

Papklp1 commented 1 week ago

是这样,从光猫的upnp关不掉

Papklp1 commented 1 week ago

把从光猫的ip屏蔽掉也是一样

╰─ sudo natter.py -v -m iptables -p 55555 -U                                  ─╯
2024-06-15 12:40:51 [I] Natter v2.1.1
2024-06-15 12:40:51 [D] fwd-iptables: Found iptables (1, 8, 10)
2024-06-15 12:40:51 [D] fwd-iptables: Creating Natter chain
2024-06-15 12:40:51 [D] fwd-iptables: Cleaning up Natter rules
2024-06-15 12:40:52 [D] stun: Got address tcp://111.111.111.111:5323 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:36207
2024-06-15 12:40:52 [D] keep-alive: Connected to host tcp://www.baidu.com:80
2024-06-15 12:40:55 [D] keep-alive: OK
2024-06-15 12:40:55 [D] stun: Got address tcp://111.111.111.111:5323 from tcp://fwa.lifesizecloud.com:3478, source tcp://192.168.1.31:36207
2024-06-15 12:40:55 [D] fwd-iptables: Adding rule tcp://192.168.1.31:36207 forward to tcp://192.168.1.31:55555
2024-06-15 12:40:55 [I] 
2024-06-15 12:40:55 [I] Scanning UPnP Devices...
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
2024-06-15 12:40:55 [D] upnp: Got URL http://192.168.1.1:49652/49652gatedesc.xml
b''
2024-06-15 12:40:56 [E] upnp: failed to load service from http://192.168.1.1:49652/49652gatedesc.xml: Invalid response from HTTP server
Traceback (most recent call last):
  File "/usr/bin/natter.py", line 1849, in <module>
    main()
  File "/usr/bin/natter.py", line 1840, in main
    natter_main(show_title)
  File "/usr/bin/natter.py", line 1730, in natter_main
    upnp_router = upnp.discover_router()
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/bin/natter.py", line 1220, in discover_router
    devs = self._discover()
           ^^^^^^^^^^^^^^^^
  File "/usr/bin/natter.py", line 1285, in _discover
    d._load_services()
  File "/usr/bin/natter.py", line 1132, in _load_services
    services_d.update(sd)
TypeError: 'NoneType' object is not iterable
2024-06-15 12:40:56 [D] fwd-iptables: Cleaning up Natter rules