端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

由本社区发起的开源项目
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#1

帖子 fuhuizn » 2008-11-25 20:17

rtorrent不支持UPNP,aMule的UNPN功能在我这里没用,郁闷,只能自己动手编了一个。
python编的,我的系统是ubuntu8.10,用的挺好,理论上windows上也能用。
包里有使用有说明(readme),欢迎有问题发邮件给我。

注意:协议字母要大写(TCP/UDP)。
附件
upnp.tar.gz
改进了适应性,请chpn兄及其他以前不能用的朋友试试现在能不能用
2008-11-29 20:33
(3.34 KiB) 已下载 915 次
上次由 fuhuizn 在 2008-12-02 14:52,总共编辑 5 次。
头像
xhy
帖子: 3916
注册时间: 2005-12-28 1:16
系统: Ubuntu 12.10 X64
来自: 火星

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#2

帖子 xhy » 2008-11-25 20:32

socket系列函数并不能保证写入全部数据,最好判断一下,否则会丢数据
目前负债150多万
头像
mawith
帖子: 1288
注册时间: 2007-10-21 16:41
来自: GD

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#3

帖子 mawith » 2008-11-25 22:51

好东西。不过现在用不着了。。 :em06
吼吼
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#4

帖子 fuhuizn » 2008-11-26 9:59

xhy 写了:socket系列函数并不能保证写入全部数据,最好判断一下,否则会丢数据
局域网速度快,是不会有问题的
头像
eagle5678
帖子: 1865
注册时间: 2006-07-08 14:07

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#5

帖子 eagle5678 » 2008-11-26 14:47

奇怪,这个不支持upnp吗
附件
screenshot1.png
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#6

帖子 fuhuizn » 2008-11-26 18:39

不是,UPNP映射表都是自动加的,不能手工加
附件
我的UPNP端口映射表
我的UPNP端口映射表
头像
eagle5678
帖子: 1865
注册时间: 2006-07-08 14:07

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#7

帖子 eagle5678 » 2008-11-26 19:24

UPNP与NAT是两个概念啊,一直以为是一样的

我弄了端口映射,可是,好像都没起作用,不知怎的
cn170355
帖子: 90
注册时间: 2008-09-12 11:48

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#8

帖子 cn170355 » 2008-11-29 7:54

好东西 但有点弄不懂
chpn
帖子: 415
注册时间: 2007-02-28 11:33

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#9

帖子 chpn » 2008-11-29 17:00

就上一个版本controlURL找不到的,p功能死的问题再问一下
这说明你的路由器没有开UPNP功能
但是我的路由器中是开启了UPNP功能的,并且在路由器中发现MusicBox 自动加了一个端口映射
controlURL找不到应该是其它问题吧
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#10

帖子 fuhuizn » 2008-11-29 17:42

chpn 写了:就上一个版本controlURL找不到的,p功能死的问题再问一下
这说明你的路由器没有开UPNP功能
但是我的路由器中是开启了UPNP功能的,并且在路由器中发现MusicBox 自动加了一个端口映射
controlURL找不到应该是其它问题吧
我是针对自己的路由器做你的,你用下面的程序测试一下,把输出贴出来给我研究研究,应该能解决了
附件
upnp.zip
这个包含测试代码,你把执行后输出的内容贴出来给我看看
(2.39 KiB) 已下载 215 次
chpn
帖子: 415
注册时间: 2007-02-28 11:33

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#11

帖子 chpn » 2008-11-30 9:01

没有任何输出
data,addr = s.recvfrom(4096) 这一关过不了
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#12

帖子 fuhuizn » 2008-11-30 10:02

里面还有个"r"命令,介绍里忘了写出来,可以重新发搜索报文,试一试吧
chpn
帖子: 415
注册时间: 2007-02-28 11:33

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#13

帖子 chpn » 2008-11-30 12:32

不管r多少次recvfrom都收不到返回数据
fuhuizn
帖子: 948
注册时间: 2006-01-06 22:55
系统: ubuntu
联系:

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#14

帖子 fuhuizn » 2008-11-30 13:27

那就没办法了
chpn
帖子: 415
注册时间: 2007-02-28 11:33

Re: 端口映射/转发工具,对用路由器(支持UPNP)上网的朋友有用

#15

帖子 chpn » 2008-12-02 9:56

装了 libupnp-1.6.6 和linux-IGD
执行
rout add -net 239.0.0.0 netmask 255.0.0.0 eth0
sudo upnpd wmaster0 wlan0
就可以成功执行p命令
但是添加删除都不成功
我是在家里装的,家里IP是192.168.13.6,在公司测试,公司IP是195.2.199.125,可下面还是出现了家里时的IP,不知道为啥
python ./upnp.py
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1800
DATE: Tue, 02 Dec 2008 01:48:43 GMT
EXT:
LOCATION: http://195.2.199.125:49153/gatedesc.xml
SERVER: Linux/2.6.27-10-generic, UPnP/1.0, Portable SDK for UPnP devices/1.6.6
X-User-Agent: redsonic
ST: upnp:rootdevice
USN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e::upnp:rootdevice


discription: http://195.2.199.125:49153/gatedesc.xml
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
<friendlyName>Linux Internet Gateway Device</friendlyName>
<manufacturer>Linux UPnP IGD Project</manufacturer>
<manufacturerURL>http://linux-igd.sourceforge.net</manufacturerURL>
<modelName>IGD Version 1.00</modelName>
<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN>
<iconList>
<icon>
<mimetype>image/gif</mimetype>
<width>118</width>
<height>119</height>
<depth>8</depth>
<url>/ligd.gif</url>
</icon>
</iconList>
<serviceList>
<service>
<serviceType>urn:schemas-dummy-com:service:Dummy:1</serviceType>
<serviceId>urn:dummy-com:serviceId:dummy1</serviceId>
<controlURL>/dummy</controlURL>
<eventSubURL>/dummy</eventSubURL>
<SCPDURL>/dummy.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WANDevice</friendlyName>
<manufacturer>Linux UPnP IGD Project</manufacturer>
<manufacturerURL>http://linux-igd.sourceforge.net</manufacturerURL>
<modelDescription>WAN Device on Linux IGD</modelDescription>
<modelName>Linux IGD</modelName>
<modelNumber>1.00</modelNumber>
<modelURL>http://linux-igd.sourceforge.net</modelURL>
<serialNumber>1.00</serialNumber>
<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN>
<UPC>Linux IGD</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
<controlURL>/upnp/control/WANCommonIFC1</controlURL>
<eventSubURL>/upnp/control/WANCommonIFC1</eventSubURL>
<SCPDURL>/gateicfgSCPD.xml</SCPDURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WANConnectionDevice</friendlyName>
<manufacturer>Linux UPnP IGD Project</manufacturer>
<manufacturerURL>http://linux-igd.sourceforge.net</manufacturerURL>
<modelDescription>WanConnectionDevice on Linux IGD</modelDescription>
<modelName>Linux IGD</modelName>
<modelNumber>0.95</modelNumber>
<modelURL>http://linux-igd.sourceforge.net</modelURL>
<serialNumber>0.95</serialNumber>
<UDN>uuid:75802409-bccb-40e7-8e6c-fa095ecce13e</UDN>
<UPC>Linux IGD</UPC>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
<controlURL>/upnp/control/WANIPConn1</controlURL>
<eventSubURL>/upnp/control/WANIPConn1</eventSubURL>
<SCPDURL>/gateconnSCPD.xml</SCPDURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>

controlURL: http://195.2.199.125:49153/upnp/control/WANIPConn1
HTTP/1.1 200 OK
SERVER: Ambit OS/1.0 UPnP/1.0 AMBIT-UPNP/1.0
EXT:
LOCATION: http://195.2.199.4:80/Public_UPNP_gatedesc.xml
CACHE-CONTROL: max-age=3600
ST: upnp:rootdevice
USN: uuid:3ef1e8fc-de3d-a8c2-38e9-b97da5deb99e::upnp:rootdevice


discription: http://195.2.199.4:80/Public_UPNP_gatedesc.xml
<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://195.2.199.4:80/</URLBase>
<device>
<deviceType>urn:schemas-upnp-org:device:InternetGatewayDevice:1</deviceType>
<presentationURL>/start.htm</presentationURL>
<friendlyName>Residential Gateway</friendlyName>
<manufacturer>NETGEAR, Inc.</manufacturer>
<manufacturerURL>http://www.NETGEAR.com</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Residential Gateway</modelName>
<UDN>uuid:3ef1e8fc-de3d-a8c2-38e9-b97da5deb99e</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:Layer3Forwarding:1</serviceType>
<serviceId>urn:upnp-org:serviceId:L3Forwarding1</serviceId>
<SCPDURL>/Public_UPNP_Layer3F.xml</SCPDURL>
<controlURL>/Public_UPNP_C1</controlURL>
<eventSubURL>/Public_UPNP_Event_1</eventSubURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANDevice:1</deviceType>
<friendlyName>WAN Device</friendlyName>
<manufacturer>NETGEAR, Inc.</manufacturer>
<manufacturerURL>http://www.NETGEAR.com</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Residential Gateway</modelName>
<UDN>uuid:b40d9e71-e99e-8e60-3911-5cd317403035</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANCommonIFC1</serviceId>
<SCPDURL>/Public_UPNP_WAND.xml</SCPDURL>
<controlURL>/Public_UPNP_C2</controlURL>
<eventSubURL>/Public_UPNP_Event_2</eventSubURL>
</service>
</serviceList>
<deviceList>
<device>
<deviceType>urn:schemas-upnp-org:device:WANConnectionDevice:1</deviceType>
<friendlyName>WAN Connection Device</friendlyName>
<manufacturer>NETGEAR, Inc.</manufacturer>
<manufacturerURL>http://www.NETGEAR.com</manufacturerURL>
<modelDescription>Residential Gateway</modelDescription>
<modelName>Residential Gateway</modelName>
<UDN>uuid:e32ab4d0-f2e5-b17c-3706-cd8fd4f8a6fc</UDN>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:WANIPConnection:1</serviceType>
<serviceId>urn:upnp-org:serviceId:WANIPConn1</serviceId>
<SCPDURL>/Public_UPNP_WANIPConn.xml</SCPDURL>
<controlURL>/Public_UPNP_C3</controlURL>
<eventSubURL>/Public_UPNP_Event_3</eventSubURL>
</service>
</serviceList>
</device>
</deviceList>
</device>
</deviceList>
</device>
</root>

controlURL: http://195.2.199.4:80/Public_UPNP_C3
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1800
DATE: Tue, 02 Dec 2008 01:48:44 GMT
EXT:
LOCATION: http://192.168.13.6:49152/gatedesc.xml
SERVER: Linux/2.6.27-10-generic, UPnP/1.0, Portable SDK for UPnP devices/1.6.6
X-User-Agent: redsonic
ST: upnp:rootdevice
USN: uuid:75802409-bccb-40e7-8e6c-fa095ecce13e::upnp:rootdevice


discription: http://192.168.13.6:49152/gatedesc.xml
>p
0 192.168.126.1 TCP 8284
1 192.168.42.1 TCP 41190
2 195.2.199.83 UDP 1704
3 195.2.199.83 UDP 1705
4 195.2.199.150 UDP 13461
5 195.2.199.150 TCP 13461
6 195.2.199.89 TCP 32452
7 195.2.199.89 UDP 32452
8 195.2.199.107 TCP 22444
9 195.2.199.150 TCP 5601
10 195.2.199.185 UDP 7600
11 195.2.199.112 TCP 29858
12 195.2.199.112 UDP 29858
13 195.2.199.186 TCP 14132
14 195.2.199.186 UDP 14132
15 192.168.1.32 UDP 12728
16 192.168.1.32 TCP 12728
17 195.2.199.99 TCP 30954
18 195.2.199.99 UDP 30954
19 195.2.199.109 UDP 15533
20 195.2.199.110 UDP 7950
21 195.2.199.111 UDP 7171
22 195.2.199.112 UDP 16502
>d s udp 16502
Fail
>a s tcp 16503
Fail
>
回复