视频地址:https://youtu.be/Ja4ZkUN-mLc
最近测试科学上网时,想测试一下IP,发现非常不方便,需求很简单,给我IP地址就行!
有一个姓不(不装了就是“不良林”)的博主,他搭建了一个链接,能直接显示出IP地址,实在是太方便了!
秉着学习的态度,我自己操作了一个,大家一起进步吧!
源码地址:
https://github.com/super-yan86/cloudflare_workers_ipinfo
测试的地址,可以直接用
https://ip.aica.cf
两段代码,其他的咱都不需要,就不贴上来
城市 ${request.cf.city}
国家/地区 ${request.cf.country}
精简代码,有能力的自己编译一下
export default {
async fetch(request) {
const body = `
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>my ip info</title>
</head>
<body>
${request.headers.get("X-Real-IP")}
</body>
`
const newResponse = new Response(body, {
headers: {
"content-type": "text/html;charset=UTF-8",
},
});
return newResponse;
},
};
没有评论:
发表评论