Skip to content

Commit

Permalink
✨ Add support for pinging IPv6 addresses and hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism authored Dec 10, 2023
1 parent 1f97be7 commit fcebd9e
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/update.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import dns from "node:dns";
import { isIP, isIPv6 } from "node:net";

import slugify from "@sindresorhus/slugify";
import dayjs from "dayjs";
import { mkdirp, readFile, writeFile } from "fs-extra";
Expand Down Expand Up @@ -152,8 +155,24 @@ export const update = async (shouldCommit = false) => {
console.log("Using tcp-ping instead of curl");
try {
let status: "up" | "down" | "degraded" = "up";
// https://github.com/upptime/upptime/discussions/888
const url = replaceEnvironmentVariables(site.url),
let address;

Check failure on line 160 in src/update.ts

View workflow job for this annotation

GitHub Actions / Build and Publish

',' expected.
if (isIP(url)) {
if (site.ipv6 && !isIPv6(url))
throw Error('Site URL must be IPv6 for ipv6 check');
address = url;
} else {
if (site.ipv6)
address = (await dns.promises.resolve6(url))[0];
else
address = (await dns.promises.resolve4(url))[0];
if (!isIP(address))
throw Error('Site IP address could not be resolved');
}

const tcpResult = await ping({
address: replaceEnvironmentVariables(site.url),
address,
attempts: 5,
port: Number(replaceEnvironmentVariables(site.port ? String(site.port) : "")),
});
Expand Down

0 comments on commit fcebd9e

Please sign in to comment.