前提:使用Cloudflare CDN
用法:在页面顶部放入代码:

<php?

$ip = getallheaders()['Cf-Connecting-Ip'];

$country = getallheaders()['Cf-Ipcountry'];

if ('CN'===$country) exit("$ip($country) not allowed");

支持ipv4和ipv6