I have some clients that loose track of UPnP ports, so I have to manually delete them. Currently I do it in luci under services upnp. How can I do it from command line. I need to write a script to check if client responds through UPnP and if not delete those ports, and then reinitate client.
do you mean you restart the daemon ?
To delete them all at once:
cat /dev/null > $(uci get upnpd.config.upnp_lease_file)
/etc/init.d/miniupnpd restart
If you want to delete them individually, or filter them, then grep
, grep -v
, or sed
will be your friends. The UI uses sed
in conjunction with the restart:
From the source:
const leasefile = uci.get('upnpd', 'config', 'upnp_lease_file');
if (access(leasefile)) {
system(['sed', '-i', '-e', `${idx}d`, leasefile]);
system(['/etc/init.d/miniupnpd', 'restart']);
}
I don't want to restart upnp, or other clients willl lose ports, so I have to initiate every other client. I'm wondering how luci delete button deletes just individual port?
You were just shown how luci does it.
Deletes the line from the lease file
Restarts the service.
If you’ve not noticed any bad behaviour from doing it via the gui then clearly this restart is fine.
Thanks, thought it maybe restart, but it just doesn't seem like it from luci, as it's done so quickly and all other active ports remain untouched, and also logread
doesn't show any miniupnpd restart
Restarting the service doesn't interfere with existing ports. It only closes those that the lease has been deleted for.
Thanks again, I understand it now and it works so I can manually remove not-working ports from /var/run/miniupnpd.leases
and do restart of miniupnpd and then client reinitiates. Would you know if I can test successfully if port is visible from outside within a script on router? Or I need to run a script on different machine, and than communicate to router what ports need to be removed?
Normally in Fedora/Ubuntu shell I would use
if nc -w2 -z $IPn $Port; then
....
fi
but lookslike busybox nc only accepts [IP] [PORT], and gives me Connection refused.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.