MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / getIpApi

Function getIpApi

speedtest/speedtest.ts:378–416  ·  view source on GitHub ↗
(ip: string)

Source from the content-addressed store, hash-verified

376}> {
377 try {
378 const response = await axios.get(
379 `http://ip-api.com/json/${ip}?fields=as,country,countryCode`
380 );
381 const data = response.data;
382
383 const asInfo = data.as?.split(" ")[0] || "";
384 const ccName =
385 data.country === "Netherlands" ? "Netherlands" : data.country || "";
386 const ccCode = data.countryCode || "";
387 const ccFlag = ccCode
388 ? String.fromCodePoint(
389 ...ccCode
390 .toUpperCase()
391 .split("")
392 .map((c: string) => 127397 + c.charCodeAt(0))
393 )
394 : "";
395
396 let ccLink = "https://www.submarinecablemap.com/country/";
397 if (["Hong Kong", "Macao", "Macau"].includes(ccName)) {
398 ccLink += "china";
399 } else {
400 ccLink += ccName.toLowerCase().replace(" ", "-");
401 }
402
403 return { asInfo, ccName, ccCode, ccFlag, ccLink };
404 } catch (error: any) {
405 console.error("Failed to get IP info:", error);
406 return { asInfo: "", ccName: "", ccCode: "", ccFlag: "", ccLink: "" };
407 }
408}
409
410async function getInterfaceTraffic(interfaceName: string): Promise<{
411 rxBytes: number;
412 txBytes: number;
413 mtu: number;
414}> {
415 try {
416 if (process.platform === "linux") {
417 const rxBytes = parseInt(
418 fs.readFileSync(
419 `/sys/class/net/${interfaceName}/statistics/rx_bytes`,

Callers 1

speedtestFunction · 0.70

Calls 2

errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected