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\r\n
HOST: 239.255.255.250:1900\r\n
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n
MAN: \"ssdp:discover\"\r\n
MX: 2\r\n\r\n HTTP/1.1 200 OK\r\n
Cache-Control: max-age=300\r\n
Date: Wed, 12 Mar 2014 10:06:19 GMT\r\n
Ext: \r\n
Location: http://192.168.99.1:1780/InternetGatewayDevice.xml\r\n
Server: POSIX UPnP/1.0 DD-WRT Linux/V24\r\n
ST: urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n
USN: uuid:40C596C5-9BF9-CB72-3586-660E4C29BD20::urn:schemas-upnp-org:device:InternetGatewayDevice:1\r\n\r\n soapbody
<?xml version=\"1.0\"?>\r\n
<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>\r\n
soappostheader
POST /control?WANIPConnection HTTP/1.1\r\n
Host: 192.168.99.1:1780\r\n
User-Agent: Ubuntu/12.04, UPnP/1.0, MiniUPnPc/1.9\r\n
Content-Length: 271\r\n
Content-Type: text/xml\r\n
SOAPAction: \"urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo\"\r\n
Connection: Close\r\n
Cache-Control: no-cache\r\n
Pragma: no-cache\r\n\r\n SOAP Response:
<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n
<s:Body>\r\n
<u:GetStatusInfoResponse xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n
<NewConnectionStatus>Connected</NewConnectionStatus>\r\n
<NewLastConnectionError>ERROR_NONE</NewLastConnectionError>\r\n
<NewUptime>451042</NewUptime>\r\n
</u:GetStatusInfoResponse>\r\n
</s:Body>\r\n
</s:Envelope>\r\n <s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n
<s:Body>\r\n
<u:GetExternalIPAddressResponse xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n
<NewExternalIPAddress>192.168.110.83</NewExternalIPAddress>\r\n
</u:GetExternalIPAddressResponse>\r\n
</s:Body>\r\n
</s:Envelope>\r\n (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\"?>\r\n
<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>\r\n 重复添加错误的相应:
<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\"?>\r\n
<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/\">\r\n
<s:Body>\r\n
<u:GetSpecificPortMappingEntryResponse xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n
<NewInternalPort>4678</NewInternalPort>\r\n
<NewInternalClient>192.168.99.40</NewInternalClient>\r\n
<NewEnabled>1</NewEnabled>\r\n
<NewPortMappingDescription>libminiupnpc</NewPortMappingDescription>\r\n
<NewLeaseDuration>0</NewLeaseDuration>\r\n
</u:GetSpecificPortMappingEntryResponse>\r\n
</s:Body>\r\n
</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
05-11 11:36