>But the thing is I manually have to open the router ports

Yeah, that's the point of them.

> Could you please guide me what should I look for so that my code can work for intenret without manually opening ports.

Not possible sorry. The whole point of firewalls is that they block unwanted traffic, and that's why they allow you to open ports; this lets you define what is wanted.

The only thing you can do is to change your code so that it works over ports that you can expect to be open. For example port 80 (http) is often open so if you code up your packets to work over HTML then you can fairly reliably get through most firewalls.