upnp端口映射:
http://bbs.csdn.net/topics/70382968
UPnP端口映射实现过程(二)
http://blog.csdn.net/jiuaiwo1314/article/details/7656446
UPnP端口映射实现过程(一)
http://blog.csdn.net/jiuaiwo1314/article/details/7656427
如何实现W5200E01-M3中的UPnP(通用即插即用) 端口转发(三)
http://blog.csdn.net/wiznet2012/article/details/7693430
MiniUPnP download zone
http://miniupnp.tuxfamily.org/files/
a command line upnp client that will allow me to write scripts to enable and disable port forwarding on my router
upnpc -a `ifconfig wlan0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1` 4668 4668 TCP upnpc -a `ifconfig wlan0 | grep "inet addr" | cut -d : -f 2 | cut -d " " -f 1` 4678 4678 UDP
upnpc-static -a 192.168.99.40 4678 4678 UDP
M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
MAN: "ssdp:discover"
MX: 2
HTTP/1.1 200 OK
Cache-Control: max-age=300
Date: Wed, 12 Mar 2014 10:06:19 GMT
Ext:
Location: http://192.168.99.1:1780/InternetGatewayDevice.xml
Server: POSIX UPnP/1.0 DD-WRT Linux/V24
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1
USN: uuid:40C596C5-9BF9-CB72-3586-660E4C29BD20::urn:schemas-upnp-org:device:InternetGatewayDevice:1
soapbody
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetStatusInfo xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1"></u:GetStatusInfo>
</s:Body></s:Envelope>
soappostheader
POST /control?WANIPConnection HTTP/1.1
Host: 192.168.99.1:1780
User-Agent: Ubuntu/12.04, UPnP/1.0, MiniUPnPc/1.9
Content-Length: 271
Content-Type: text/xml
SOAPAction: "urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo"
Connection: Close
Cache-Control: no-cache
Pragma: no-cache
SOAP Response:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetStatusInfoResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewConnectionStatus>Connected</NewConnectionStatus>
<NewLastConnectionError>ERROR_NONE</NewLastConnectionError>
<NewUptime>451042</NewUptime>
</u:GetStatusInfoResponse>
</s:Body>
</s:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetExternalIPAddressResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewExternalIPAddress>192.168.110.83</NewExternalIPAddress>
</u:GetExternalIPAddressResponse>
</s:Body>
</s:Envelope>
(gdb) p *urls
$20 = {controlURL = 0x8113830 "http://192.168.99.1:1780/control?WANIPConnection",
ipcondescURL = 0x81137e0 "http://192.168.99.1:1780/x_wanipconnection.xml",
controlURL_CIF = 0x8113880 "http://192.168.99.1:1780/control?WANCommonInterfaceConfig",
controlURL_6FC = 0x8113718 "http://192.168.99.1:1780/", rootdescURL = 0x81138e0 "http://192.168.99.1:1780/InternetGatewayDevice.xml"}
AddPortMapping
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewRemoteHost></NewRemoteHost>
<NewExternalPort>4678</NewExternalPort>
<NewProtocol>UDP</NewProtocol>
<NewInternalPort>4678</NewInternalPort>
<NewInternalClient>192.168.99.48</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>libminiupnpc</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</u:AddPortMapping>
</s:Body>
</s:Envelope>
重复添加错误的相应:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>402</errorCode>
<errorDescription>Invalid Argument</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
GetSpecificPortMappingEntry:
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetSpecificPortMappingEntry xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewRemoteHost></NewRemoteHost>
<NewExternalPort>4678</NewExternalPort>
<NewProtocol>UDP</NewProtocol>
</u:GetSpecificPortMappingEntry>
</s:Body>
</s:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:GetSpecificPortMappingEntryResponse xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewInternalPort>4678</NewInternalPort>
<NewInternalClient>192.168.99.40</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>libminiupnpc</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</u:GetSpecificPortMappingEntryResponse>
</s:Body>
</s:Envelope>
可以在谷歌上这样搜索关键字:upnp port forwarding c
miniupnp官网
http://miniupnp.tuxfamily.org/files/
java版本的upnp端口映射:
http://upnp-portmapper.sourceforge.net/
java -jar PortMapper-1.9.6.jar -h usage: java -jar PortMapper.jar [-a <ip port external_port protocol> | -d <external_port protocol [...]> | -g | -h | -l | -r <port protocol [...]> | -s] [-i <index>] [-u <class name>] -a <ip port external_port protocol> Add port forwarding -d <external_port protocol [...]> Delete port forwarding -g Start graphical user interface (default) -h print this message -i <index> Router index (if more than one is found) -l List forwardings -r <port protocol [...]> Add all forwardings to the current host -s Get Connection status -u <class name> UPnP library Protocol is UDP or TCP UPnP library class names: - org.chris.portmapper.router.sbbi.SBBIRouterFactory (default) - org.chris.portmapper.router.weupnp.WeUPnPRouterFactory - org.chris.portmapper.router.dummy.DummyRouterFactory