andrea
andrea

Reputation: 522

port mapping using miniupnp and libnatpmp

I am using miniupnp to add a port mapping to a router, the port is mapped for a "lease" amount of time, I am using a random 10 hours at the moment, my question is:

after the port is successfully mapped should I ping the router periodically to check if the port is still mapped (for example every minute or even less) or do I trust the router to keep the port mapped for the whole duration of the lease, and only check few minutes before the lease expires to renew it ?

Similarly after a successful port mapping another call is made to retrieve the external IP address, do I trust that this IP will not change or should I keep pinging every few seconds (or minutes?) to verify that the external IP address has not changed ?

Upvotes: 1

Views: 1570

Answers (2)

miniupnp
miniupnp

Reputation: 96

Unfortunately you cannot rely on Home routers to properly fire the right events in case the IP change or a mapping is not good anymore.

I advice to periodically (every few minutes) call GetSpecificPortMappingEntry() and/or GetExternalIPAddress()

Upvotes: 1

Franck Kallaway
Franck Kallaway

Reputation: 79

You can subscribe to UPnP event of WAN***Connection (PPP or IP) and catch the event "PortMappingNumberOfEntries".

I hope this helps.

Upvotes: 2

Related Questions