惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
C
Cybersecurity and Infrastructure Security Agency CISA
S
Secure Thoughts
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Hacker News: Ask HN
Hacker News: Ask HN
Attack and Defense Labs
Attack and Defense Labs
N
News and Events Feed by Topic
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
A
Arctic Wolf
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The GitHub Blog
The GitHub Blog
W
WeLiveSecurity
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
Y
Y Combinator Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Forbes - Security
Forbes - Security
NISL@THU
NISL@THU
博客园 - 聂微东
G
Google Developers Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Schneier on Security
Schneier on Security
V
Vulnerabilities – Threatpost
V
V2EX
I
Intezer
S
Schneier on Security
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
雷峰网
雷峰网
L
LangChain Blog
小众软件
小众软件
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
L
LINUX DO - 热门话题
P
Proofpoint News Feed
Microsoft Security Blog
Microsoft Security Blog
Project Zero
Project Zero
V
Visual Studio Blog
Engineering at Meta
Engineering at Meta
爱范儿
爱范儿
H
Hacker News: Front Page
B
Blog
T
Threatpost
Spread Privacy
Spread Privacy
H
Heimdal Security Blog
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Cloudflare Blog

daliy on 打工人日志

iStoreOS(旁路由)使用openclash实现dns劫持 异常流量分析:图片库服务黑客入侵 openwrt 硬盘扩容 【福利】免费!本地部署!去除视频中移动的物体 通知:《打工人日报》迁移到独立板块 KyBook 3 | calibre-web - IOS系统最佳图书伴侣 iOS 17 「待机显示」适配普通 iPhone(非 Pro/Max),屏幕在充电时常亮 【福利】埃隆·马斯克传 [沃尔特·艾萨克森] 在线下载 【破解】小鹏P5和小鹏G9开启adb和网络adb 3D Gaussian Splatting:3D模型渲染 2023亚运会电竞门票民购买指南(报名+抽签) 大麦抢票辅助软件(福利 TFBOYS十年之约演唱会 2023 全机位 视频) 最好的微信朋友圈集赞神器-福利推荐 2010年的天涯神贴聊房价 github 国内代理访问下载 逆境和成长-2022年终总结 优雅的使用Conda管理python环境 shell功能脚本集合 headscale 部署使用 羊了个羊小程序 破解通关 logrotate 日志滚动的使用 rsync 文件同步 163企业邮箱设置教程 2021年第50周记 优秀英语教材的选择
搭建ip地址检索服务
2024-10-11 · via daliy on 打工人日志

很多时候,我们需要查询一个IP地址,都得通过百度,谷歌,或者其他搜索引擎,非常麻烦。教大家一个使用cloudflare worker搭建一个只属于我们自己的ip地址检索服务。

  1addEventListener('fetch', event => {
  2  event.respondWith(handleRequest(event.request));
  3});
  4
  5/**
  6 * Handle the incoming request and return formatted IP information
  7 * @param {Request} request
  8 */
  9async function handleRequest(request) {
 10  const url = new URL(request.url);
 11  const queryIp = url.searchParams.get('ip');
 12  const clientIp = queryIp || request.headers.get('cf-connecting-ip');
 13  const path = url.pathname;
 14
 15  // 获取 IP 信息
 16  const ipInfo = await getIpInfo(clientIp);
 17
 18  // 根据路径选择返回格式
 19  if (path === '/table') {
 20    const tableFormat = formatAsTable(ipInfo);
 21    return new Response(tableFormat, {
 22      headers: { 'Content-Type': 'text/plain; charset=utf-8' },
 23      status: 200,
 24    });
 25  } else {
 26    return new Response(JSON.stringify(ipInfo), {
 27      headers: { 'Content-Type': 'application/json' },
 28      status: 200,
 29    });
 30  }
 31}
 32
 33/**
 34 * Get IP information and format it according to the required structure
 35 * @param {string} ip
 36 */
 37async function getIpInfo(ip) {
 38  try {
 39    const response = await fetch(`http://ip-api.com/json/${ip}`);
 40    const data = await response.json();
 41
 42    // Format the returned data
 43    return {
 44      ip: data.query || ip,
 45      city: data.city || "None",
 46      province: data.regionName || "None",
 47      country: data.country || "None",
 48      continent: data.continent || "None",
 49      isp: data.isp || "None",
 50      time_zone: data.timezone || "None",
 51      latitude: data.lat || 0,
 52      longitude: data.lon || 0,
 53      postal_code: data.zip || "None",
 54      iso_code: data.countryCode || "None",
 55      notice: "Let it be",
 56      provider: "Powered by Jobcher",
 57      blog: "https://www.jobcher.com",
 58      data_updatetime: new Date().toISOString().slice(0, 10).replace(/-/g, '')
 59    };
 60  } catch (error) {
 61    return {
 62      ip: ip,
 63      city: "None",
 64      province: "None",
 65      country: "None",
 66      continent: "None",
 67      isp: "None",
 68      time_zone: "None",
 69      latitude: 0,
 70      longitude: 0,
 71      postal_code: "None",
 72      iso_code: "None",
 73      notice: "Let it be",
 74      provider: "Powered by Jobcher",
 75      blog: "https://www.jobcher.com",
 76      data_updatetime: new Date().toISOString().slice(0, 10).replace(/-/g, '')
 77    };
 78  }
 79}
 80
 81/**
 82 * Format the IP information as a table-like structure
 83 * @param {Object} info
 84 */
 85function formatAsTable(info) {
 86  const pad = (str, length) => str.toString().padEnd(length, ' ');
 87  const keyWidth = 20;  // Adjusted width for keys
 88  const valueWidth = 60; // Adjusted width for values
 89
 90  const lineBorder = (keyLength, valueLength) =>
 91    `┏${'━'.repeat(keyLength)}${'━'.repeat(valueLength)}┓`;
 92  const lineMiddle = (keyLength, valueLength) =>
 93    `┡${'━'.repeat(keyLength)}${'━'.repeat(valueLength)}┩`;
 94  const lineEnd = (keyLength, valueLength) =>
 95    `└${'─'.repeat(keyLength)}${'─'.repeat(valueLength)}┘`;
 96
 97  const borderTop = lineBorder(keyWidth+2, valueWidth+2);
 98  const borderMiddle = lineMiddle(keyWidth+2, valueWidth+2);
 99  const borderBottom = lineEnd(keyWidth+2, valueWidth+2);
100
101  const lines = [
102    '                                  ip.jobcher.com                               ',
103    borderTop,
104    `┃ ${pad('key', keyWidth)}${pad('value', valueWidth)} ┃`,
105    borderMiddle,
106    `│ ${pad('ip', keyWidth)}${pad(info.ip, valueWidth)} │`,
107    `│ ${pad('city', keyWidth)}${pad(info.city, valueWidth)} │`,
108    `│ ${pad('province', keyWidth)}${pad(info.province, valueWidth)} │`,
109    `│ ${pad('country', keyWidth)}${pad(info.country, valueWidth)} │`,
110    `│ ${pad('continent', keyWidth)}${pad(info.continent, valueWidth)} │`,
111    `│ ${pad('isp', keyWidth)}${pad(info.isp, valueWidth)} │`,
112    `│ ${pad('time_zone', keyWidth)}${pad(info.time_zone, valueWidth)} │`,
113    `│ ${pad('latitude', keyWidth)}${pad(info.latitude, valueWidth)} │`,
114    `│ ${pad('longitude', keyWidth)}${pad(info.longitude, valueWidth)} │`,
115    `│ ${pad('postal_code', keyWidth)}${pad(info.postal_code, valueWidth)} │`,
116    `│ ${pad('iso_code', keyWidth)}${pad(info.iso_code, valueWidth)} │`,
117    `│ ${pad('notice', keyWidth)}${pad(info.notice, valueWidth)} │`,
118    `│ ${pad('', keyWidth)}${pad('©2020-01-01->now', valueWidth)} │`,
119    `│ ${pad('provider', keyWidth)}${pad(info.provider, valueWidth)} │`,
120    `│ ${pad('blog', keyWidth)}${pad(info.blog, valueWidth)} │`,
121    `│ ${pad('data_updatetime', keyWidth)}${pad(info.data_updatetime, valueWidth)} │`,
122    borderBottom,
123    ` `,
124  ];
125
126  return lines.join('\n');
127}
1# 查询本地ip
2curl ip.jobcher.com
1# 查询指定ip
2curl ip.jobcher.com?ip=1.1.1.1
1curl ip.jobcher.com/table
1curl ip.jobcher.com/table?ip=1.1.1.1