A drowning person is extremely dangerous because the animal instinct in them will cause them to push a rescuer underwater so the victim can climb on top. We don't blame the drowning person, we know that humans will do terrible things when they're in mortal danger.
So perhaps the rich countries that caused much of this pollution can find a way to incorporate all the people who will need a new place to stay, making them productive citizens. Instead of destroying their land and then machine gunning them at the border.
This cuts both ways. Without all the civilization and tech brought by the rich countries Central America (or Africa, etc) would not be able to reproduce at the problematic rates they are today. If that is also the rich countries responsibility we should be immediately cutting off all aid or enforcing birth limits.
We also need that in our own countries, but our naturally dwindling birth rates seem to have that covered for now. We should codify sustainable reproduction rates.
Then there are the physical realities - borders are not magical unbroken fences. Most (of the interesting ones, for migration) have huge quantities of legal people and goods moving across them. If the "migrants" are numerous, and there are plenty of "legals" who know how lucrative the people smuggling trade can be...
Sorting who's illegal? Inside the country, sure, it's not obvious. But at the point of entry? Any crossing outside of the designated point of entry - you get a bullet, no questions asked. No one will check if you are a citizen or have a right to enter. Simply a sign "use of deadly force is authorised" and armed patrols 24/7 with enough ammo to stop even large infiltrations.
At the point of entry? You gotta have a passport and a visa. No need for violence. You are just denied entry. Price of mistake is a bus ticket back. What's hard about it?
As for refugees, sure this is a good concept but they should be by invitation only. You escape to whatever country you can escape, then prepare and file papers in the embassy and wait. If there is more perceived propaganda value ("North Korean official escaped Kim regime") or factual ("Russian submarine designer with a suitcase of blueprints") of inviting you than perceived costs of threat, sure welcome, otherwise, why?
Refugee status (just as ANY immigration) exists for the benefit of accepting country. Not for the benefit of the refugee or immigrant themselves.