Skip to content

Commit

Permalink
初始化版本
Browse files Browse the repository at this point in the history
  • Loading branch information
sunhao committed Apr 8, 2022
1 parent f075e31 commit 08fc86e
Show file tree
Hide file tree
Showing 13 changed files with 1,806 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# utools-dig
基于nodejs实现的跨平台域名解析工具

>出于跨平台考虑使用了nodejs实现,没有调用二进制命令,所以功能并没有实际linux上的dig命令那么强大
开源地址: [utools-dig](https://github.com/fnoopv/utools-dig)

todo:
[ ] 更明确的报错信息
[ ] 支持其他类型的DNS解析
[ ] 支持从utools输入框匹配解析
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/src/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Dig</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "utools-dig",
"private": true,
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"antd": "^4.19.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
},
"devDependencies": {
"@vitejs/plugin-react": "^1.0.7",
"less": "^4.1.2",
"vite": "^2.9.0",
"vite-plugin-imp": "^2.1.7"
}
}
Binary file added public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions public/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"main": "index.html",
"logo": "logo.png",
"preload": "preload.js",
"pluginSetting": {
"single": false
},
"features": [
{
"code": "dig",
"explain": "高级域名解析",
"cmds": [
"dig",
"域名",
{
"type": "regex",
"label": "解析域名",
"match": "/^([a-z0-9]+(-[a-z0-9]+)*\\.)+[a-z]{2,}$/",
"minLength": 4
}
]
}
]
}
27 changes: 27 additions & 0 deletions public/preload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const { Resolver } = require("dns").promises;

window.query = async (values) => {
const addresses = [];

const resolverOption = {
timeout: 5,
tries: 3,
};

const resolver = new Resolver(resolverOption);
resolver.setServers([values.dns]);

await resolver.resolve(values.domain, values.type).then(
(res) => {
for (const value of res) {
addresses.push({domain: values.domain, type: values.type, result: value})
}
console.log("resss: ", res);
},
(err) => {
console.log("err: ", err);
}
);
console.log("result: ", addresses);
return addresses;
};
19 changes: 19 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.App {
padding: 10px;
}

.queryResult {
margin: 10px;
}

.domainTitle {
text-align: center;
font-size: 40px;
font-weight: bold;
margin: 0 auto;
}

.domainResult {
font-size: 18px;
font-weight: bolder;
}
172 changes: 172 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import React, { useState, useEffect } from "react";
import { Form, Row, Col, Input, Button, Select, Empty, Table } from "antd";
import { DownOutlined, UpOutlined } from "@ant-design/icons";
import "./App.css";

const { Option } = Select;

const App = () => {
const [expand, setExpand] = useState(false);
const [address, setAddress] = useState([]);
const [queryValue, setQueryValue] = useState({})

const reg = new RegExp('[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9](?:\.[a-zA-Z]{2,})+')
const [form] = Form.useForm();

const defaultQuery = {
domain: "",
type: "A",
dns: "114.114.114.114",
};

useEffect(() => {
window.utools.onPluginEnter(({ code, type, payload }) => {
console.log("用户进入插件", code, type, payload);
});
});

const getFields = () => {
const children = [
<Col span={6} offset={4} key="type">
<Form.Item name="type" label="记录类型">
<Select>
<Option value="A">A</Option>
<Option value="AAAA">AAAA</Option>
<Option value="CNAME">CNAME</Option>
<Option value="NS">NS</Option>
<Option value="PTR">PTR</Option>
<Option value="TXT">TXT</Option>
</Select>
</Form.Item>
</Col>,
<Col span={8} key="dns">
<Form.Item name="dns" label="DNS服务器">
<Select>
<Option value="114.114.114.114">114.114.114.114</Option>
<Option value="119.29.29.29">119.29.29.29</Option>
<Option value="223.5.5.5">223.5.5.5</Option>
<Option value="8.8.8.8">8.8.8.8</Option>
</Select>
</Form.Item>
</Col>,
];

return children;
};

async function queryDomain(values) {
setQueryValue(values);
const result = await query(values);
for (const val of result) {
if (!(val.result instanceof Array)) {
if (reg.test(val.result)) {
const endResult = await query({domain: val.result, type: "A", dns: queryValue.dns})
console.log("endResult: ", endResult)
result.push(...endResult)
} else {
console.log("no match")
}
}
}
setAddress(result);
}

async function query(values) {
const r2 = await window.query(values);
console.log("r2: ", r2)
return r2;
}

const columns = [
{
title: "域名",
dataIndex: "domain"
},
{
title: "记录类型",
dataIndex: "type"
},
{
title: "记录值",
dataIndex: "result"
}
]

const resultList = () => {
return (
<Table dataSource={address} columns={columns} rowKey={address.domain} pagination={false} size="small" />
);
};

return (
<div className="App">
<Form
form={form}
name="dig"
className="ant-advanced-search-form"
onFinish={queryDomain}
initialValues={defaultQuery}
>
<Row gutter={24}>
<Col span={12} offset={6} key="domain">
<div className="domainTitle">域名解析</div>
<Form.Item
name="domain"
rules={[
{
required: true,
message: "必须输入域名!",
},
]}
>
<Input placeholder="输入域名" size="large" autoFocus />
</Form.Item>
</Col>
</Row>
<Row gutter={24}>{getFields()}</Row>
<Row>
<Col
span={24}
style={{
textAlign: "right",
}}
>
<Button type="primary" htmlType="submit">
解析
</Button>
<Button
style={{
margin: "0 8px",
}}
onClick={() => {
form.resetFields();
}}
>
重置
</Button>
<a
style={{
fontSize: 12,
}}
onClick={() => {
setExpand(!expand);
setAddress("");
}}
>
{expand ? <UpOutlined /> : <DownOutlined />} 高级选项
</a>
</Col>
</Row>
</Form>
<div className="queryResult">
{address.length > 0 ? (
resultList()
) : (
<Empty description={<span>暂无解析</span>} />
)}
</div>
</div>
);
};

export default App;
15 changes: 15 additions & 0 deletions src/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
9 changes: 9 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import App from './App'

ReactDOM.render(
<App />,
document.getElementById('root')
)
23 changes: 23 additions & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import vitePluginImp from 'vite-plugin-imp'

// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [react(), vitePluginImp({
libList: [
{
libName: 'antd',
style: (name) => `antd/es/${name}/style/index.js`
}
]
})],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
}
})
Loading

0 comments on commit 08fc86e

Please sign in to comment.