Update hosts form

This commit is contained in:
2026-09-20 12:51:12 +01:00
parent 8b40a876a1
commit a9ebd8fb75
13 changed files with 198 additions and 67 deletions
@@ -0,0 +1,25 @@
import { execSync } from "node:child_process";
/**
* Get the local IPv4 address of a specific network interface
* @param interface_name Network interface name (e.g. "enp2s0")
* @returns Local IP address or empty string
*/
export default async function getInterfaceLocalIP(
interface_name: string | null,
): Promise<string> {
if (!interface_name) return ``;
try {
const output = execSync(
`ip -4 addr show ${interface_name}`,
{ encoding: "utf-8" },
).trim();
const match = output.match(
/inet\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/\d+/,
);
if (match && match[1]) {
return match[1];
}
} catch (error) {}
return ``;
}
@@ -3,11 +3,16 @@ import { execSync } from "node:child_process";
/**
* Function to grab the host's public
* IP address
* @param param0
* @param interface_name Optional network interface to use
*/
export default async function grabHostPublicIPAddress() {
export default async function grabHostPublicIPAddress(
interface_name?: string | null,
) {
try {
const public_ip = execSync(`curl -sS --max-time 15 https://api.ipify.org`, {
const curl_cmd = interface_name
? `curl -sS --max-time 15 --interface ${interface_name} https://api.ipify.org`
: `curl -sS --max-time 15 https://api.ipify.org`;
const public_ip = execSync(curl_cmd, {
encoding: "utf-8",
})
.trim();