I would love to know the context behind why you are trying to achieve this? What is the end goal?
Carrying this out would require advanced coding, and so requires hiring a Shopify expert to carry this out. Would removing the specific countries from the approved shipping zones be an option? Then customers from these countries will not be able to complete checkout, they will see an error stating that their region is not supported. This guide outlines how to do this. Another option which may work for is using a third party app that can block access from specific countries, here's an example of an app that carries this out.
I hope this helps!
Ivy | Social Care @ Shopify - Was my reply helpful? Click Like to let me know! - Was your question answered? Mark it as an Accepted Solution - To learn more visit the Shopify Help Center or the Shopify Blog