[英]Android port forwarding
如何使用來自其他設備的IP從Android設備轉發到路由器?
我想從android設備外部連接到路由器公共IP:端口,以便我可以訪問連接到路由器的硬件設備。(Android - >外部IP:端口) - >路由器 - >硬件設備(硬件設備有它自己的IP和mac)。
碼:
PortMapping mapping = new PortMapping();
UnsignedIntegerTwoBytes externalPort = new UnsignedIntegerTwoBytes(22555L);
UnsignedIntegerTwoBytes internalPort = new UnsignedIntegerTwoBytes(80L);
mapping.setDescription("HardwareDescription");
mapping.setEnabled(true);
mapping.setExternalPort(externalPort);
mapping.setInternalClient("192.168.2.68");
mapping.setInternalPort(internalPort);
mapping.setProtocol(PortMapping.Protocol.TCP);
mapping.setRemoteHost("192.168.2.254");
mUpnpService = new MyUpnpServiceImpl(new PortMappingListener(mapping));
mUpnpService.getRouter();
mUpnpService.getControlPoint().search(SCAN_TIMEOUT);
UpnpServiceImpl:
private class MyUpnpServiceImpl extends UpnpServiceImpl {
public MyUpnpServiceImpl(RegistryListener... listeners) {
super(new AndroidUpnpServiceConfiguration(getWifiManager()),
listeners);
}
@Override
public Router getRouter() {
return super.getRouter();
}
@Override
protected Router createRouter(ProtocolFactory protocolFactory,
Registry registry) {
return new AndroidWifiSwitchableRouter(configuration,
protocolFactory, getWifiManager(), getConnectivityManager());
}
}
上面的代碼不會崩潰,但它也不會創建任何端口!
這可能嗎? 如果答案是肯定的,你能否指出我正確的方向。
找到了這個問題的答案。 第一步是在路由器上啟用UPNP選項,在此步驟之后導入庫net.sbbi.upnp搜索路由器(IGD)設備並使用方法addPortMapping 。
以下是任何想要使用任何IP在路由器上打開o端口的示例,而不僅僅是應用程序運行的當前設備。
您必須通過桌面與任何資源管理器(iexplorer,chrome等)連接到您的路由器嘗試連接到地址192.168.1.1
(您的gateway
,從cmd
窗口執行ipconfig
,你會看到一行說什么是你的gateway
[路由器]),輸入路由器的用戶名和密碼並進行配置。 取決於路由器和型號,請參閱路由器手冊。 尋找有關NAT
, Port Forward
或Virtual Server
。 您可以打開單個端口或一系列端口,鍵入應轉發這些端口的IP地址,在這種情況下是設備的IP。 如有任何疑問,請在互聯網上搜索路由器的名稱以及如何打開/轉發端口。
祝好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.