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

Function executeDig

dig/dig.ts:158–202  ·  view source on GitHub ↗
(args: string[])

Source from the content-addressed store, hash-verified

156 const hasAnyPlusOption = modifiedArgs.some((arg) => arg.startsWith("+"));
157 const isSimpleQuery =
158 !hasAnyPlusOption && !modifiedArgs.some((arg) => arg.startsWith("-"));
159
160 if (isSimpleQuery) {
161 modifiedArgs.push("+short");
162 }
163
164 // Use execFile to pass args as array — no shell interpolation
165 const { stdout, stderr } = await execFilePromise("dig", modifiedArgs, { timeout: 20000 });
166
167 if (stderr && !stdout) {
168 throw new Error(`dig 命令执行失败: ${stderr}`);
169 }
170
171 const hasShortOutput = modifiedArgs.includes("+short");
172
173 return {
174 success: true,
175 output: stdout.trim(),
176 isShortOutput: hasShortOutput,
177 };
178 } catch (error: any) {
179 console.error("Dig execution error:", error);
180
181 if (
182 error.message?.includes("not found") ||
183 error.message?.includes("not recognized")
184 ) {
185 throw new Error(
186 "系统未安装 dig 工具。请安装 bind-utils (Linux) 或 dnsutils (Ubuntu/Debian) 包。"
187 );
188 }
189
190 throw new Error(`DNS 查询失败: ${error.message || error}`);
191 }
192}
193
194async function formatShortDnsResults(
195 output: string,
196 args: string[]
197): Promise<string> {
198 if (!output || output.trim() === "") {
199 return `❌ <b>解析失败</b>
200
201无记录或查询失败`;
202 }
203
204 const lines = output.split("\n").filter((line) => line.trim() !== "");
205

Callers 1

digFunction · 0.85

Calls 2

sanitizeDigArgsFunction · 0.85
errorMethod · 0.80

Tested by

no test coverage detected