我正在尝试从专用网络外部的设备到专用网络内部和NAT后面的设备进行p2p连接 .
我正在使用lib net.sb..nnp将路由映射添加到我的路由器 .
import net.sbbi.upnp.impls.InternetGatewayDevice;
import net.sbbi.upnp.messages.UPNPResponseException;
.....
uPnPPortMapper = new UPnPPortMapper();
try {
uPnPPortMapper.openRouterPort(externalIP, externalPort,internalIP,internalPort, ApplicationConstants.ADD_PORT_DESCRIPTION);
} catch (IOException e) {
e.printStackTrace();
} catch (UPNPResponseException e) {
e.printStackTrace();
}
public boolean openRouterPort(String externalRouterIP,int externalRouterPort, String internalIP,int internalPort, String description) throws IOException, UPNPResponseException {
/** Upnp devices - router search*/
if(internetGatewayDevices == null){
internetGatewayDevices = InternetGatewayDevice.getDevices(ApplicationConstants.SCAN_TIMEOUT);
}
if(internetGatewayDevices != null){
for (InternetGatewayDevice addIGD : internetGatewayDevices) {
addIGD.addPortMapping(description, externalRouterIP, internalPort, externalRouterPort, internalIP, 0, ApplicationConstants.TCP_PROTOCOL);
addIGD.addPortMapping(description, externalRouterIP, internalPort, externalRouterPort, internalIP, 0, ApplicationConstants.UDP_PROTOCOL);
}
return true;
}else{
return false;
}
}
这段代码确实在我的路由器中添加了一个端口映射,就像你在我的TP Link TL-WR940ND的UPnP表中看到的那样:
当前的UPnP设置列表
ID App说明外部端口协议内部端口IP地址状态
1 Skype UDP at 192.168.0.101:3105 31051 UDP 31051 192.168.0.101已启用
2 Skype TCP at 192.168.0.101:3105 31051 TCP 31051 192.168.0.101已启用
3使用UNPN打开IGD端口31052 TCP 31052 192.168.0.102启用
4使用UNPN 31052在IGD上打开端口UDP 31052 192.168.0.102已启用
问题是,当我尝试 Build 从网络外部到我的公共IP端口31052的连接时,我收到超时 .
我正在使用该站点(http://www.ipfingerprints.com/portscan.php)来检查端口状态,并且端口31052被标记为'filtered'而skype 's port is marked as ' open':
港口国服务
31051 / tcp打开未知
31052 / tcp过滤未知
我在我的路由器上没有找到任何其他设置,skype可能会像防火墙规则那样改变以使端口打开 .
我已经测试了一些应用程序,如'Droid UPnP Port Mapper'(Android应用程序)和'UPnP PortMapper'(Windows应用程序),但他们都成功地在我的路由器内创建了一个端口映射,但没有一个让端口'打开' .
我的路由器不在双NAT后面,因为http://www.ipfingerprints.com/给出的外部IP是189.xx.xxx.xxx,也是我的路由器WAN IP .