1
我建立一个简单的插座,其将接受在端口1337 连接它通过本地主机接受连接:UPnP的端口映射,服务不接受连接
$ nc -vv localhost 1337
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif lo0
src ::1 port 57224
dst ::1 port 1337
rank info not available
TCP aux info available
Connection to localhost port 1337 [tcp/menandmice-dns] succeeded!
^C
我使用可可端口映射器(https://github.com/mugginsoft/Cocoa-PortMapper)转发此端口到NAT路由器我落后了。
portMapper = [[PortMapper alloc] initWithPort:1337];
portMapper.desiredPublicPort = 1337;
[[NSNotificationCenter defaultCenter] addObserverForName:PortMapperChangedNotification object:portMapper queue:nil usingBlock:^(NSNotification *note) {
NSLog(@"Successfully mapped: %@", portMapper.isMapped ? @"YES" : @"NO");
NSLog(@"Mapped %@:%hu", portMapper.publicAddress, portMapper.publicPort);
}];
if(![portMapper waitTillOpened]) {
NSLog(@"Could not open port");
}
它返回YES,并在我的路由器的UPnP端口映射表,我可以看到有一个外部端口1337上的活动TCP映射到内部端口1337上的我的电脑本地IP。
然而,通过外部IP连接服务无法正常工作:
$ nc -vv xxx.89.136.xx 1337
nc: connectx to xxx.89.136.xx port 1337 (tcp) failed: Connection refused
如果我在路由器手动设置端口转发规则,连接正常。即使我的路由器说它工作,为什么不UPnP端口映射工作?
同样的事情发生在我身上! – simernes