How can I make a port forwarding from a android device to router using the IP from another device?
I want to connect from android device externally to a routers public ip:port so that I can access the hardware device that is connected to the router.(Android -> external IP:Port) -> Router -> hardware Device(hardware device has its own IP and mac).
Code:
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());
}
}
The code above doesn't crash, but also it doesn't create any port!
Is this possible? If the answer is yes, can you point me in the right direction.
On the Mobile Hotspot Homepage, click the Advanced Settings icon. Go to Router > Port Forward. Select Enable option beside "Port Forwarding".
You won't have any use port forwarding a mobile Hotspot connection. The IP address assigned to a mobile device is generally a CG-NAT private address, and forwarding that won't help you achieve a publicly reachable host.
Found the answer for this question. The first step is to enable the UPNP option on router, after this step import the library net.sbbi.upnp search for the router (IGD) device and use the method addPortMapping.
Here is an example for anyone that want to open o port on router using any IP, not just from the current device that the app runs.
https://github.com/ManolescuSebastian/Port_Forward_Android
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With