In the case of United States Army Coast Artillery Corps defenses in World War II, a Harbor Entrance Control Post on shore would interrogate a vessel, and a nearby examination battery would be ready to respond if required.
Duties might include boarding ships, examining papers to establish identity and belligerent status, and inspecting cargoes for legitimacy.
As an example of how an examination service might operate, here is an account of the procedure that operated in 1917 in Sydney Harbour: "At midnight on 7 August all traffic entering and leaving the harbour was placed under strict naval control with the inauguration of an examination service under Captain Pasco's port defense organisation, to guard against surprise attack by disguised armed merchant ship raiders.
No incoming ship could approach beyond the line between Flat Point and Cranberry Head without first establishing its identity to a naval examination vessel.
Vessels wishing to leave port would have to notify the examination one day in advance and receive, confidentially, a time when the gate would be briefly opened.