| 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 | |
| 410 | async 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`, |