添加windows主机名发现和按需挂载共享工具.

This commit is contained in:
tsf committed 2026-11-06 11:41:59 +08:00
commit d7b8a21ca5
12 files changed
+2119

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
# tools-linux
Linux 局域网小工具集,当前包含两个与 Windows 互通相关的工具。
> Linux utilities for Windows hostname discovery and SMB share automounting.
仅建议在可信局域网中使用。
## 工具
| 工具 | 作用 | 文档 |
| --- | --- | --- |
| [windiscover](windiscover/) | 通过 NetBIOS 自动发现 Windows 主机名,维护 `/etc/hosts` | [README](windiscover/README.md) |
| [winshare](winshare/) | 通过 CIFS + systemd automount 按需挂载 Windows SMB 共享 | [README](winshare/README.md) |
## 环境要求
- Linux + systemd
- Python 3.8+(windiscover;winshare 的卸载脚本也需要 python3)
- bash、iproute2、util-linux(`mountpoint`、`findmnt`)
- `cifs-utils`:Debian/Ubuntu 系由 winshare 自动安装;其他发行版请预先安装
- root 权限(systemd、`/etc/hosts`、`/etc/fstab`、SMB 凭据文件)
在 Ubuntu 26.04 上测试。
## 快速开始
### Windows 主机名自动发现
```bash
cd windiscover
sudo bash install.sh
windiscover # 查看发现的主机
```
安装后 systemd timer 每 5 分钟更新 `/etc/hosts` 中的托管区块。支持
`windiscover`、`sudo windiscover --sweep-all --update-hosts`、
`sudo windiscover --remove` 等命令。
### Windows 共享按需自动挂载
```bash
cd winshare
sudo bash setup-winshare.sh
```
按提示输入 Windows 主机、共享名、挂载点和账号密码。默认访问挂载点时自动
挂载,空闲 10 分钟自动卸载。
## 卸载
```bash
cd windiscover && sudo bash uninstall.sh
cd winshare && sudo bash remove-winshare.sh
```
## 工作原理
- **windiscover**:向本机各 IPv4 网段的广播地址、主 `/24`、轮换本地 `/24`
以及 ARP 邻居发送 NetBIOS 节点状态查询(NBSTAT,UDP/137),解析 `<00>`
名称后写入 `/etc/hosts` 的托管区块,并用 systemd timer 定期刷新。
- **winshare**:交互式生成 SMB 凭据文件(0600,root)和 `/etc/fstab` 条目,
通过 `x-systemd.automount` 实现按需挂载;卸载脚本负责清理配置。
## 安全说明
- NetBIOS 名称应答没有认证,局域网内任何主机都可以伪造应答(名称投毒)。
windiscover 只采集名称和地址,不执行应答内容,但仍建议只在可信局域网使用。
- winshare 的 SMB 密码保存在 `/etc/samba/credentials/` 下(0600,root),
`/etc/fstab` 只引用凭据文件路径,不包含密码。
- windiscover 只修改 `/etc/hosts` 中带标记的托管区块;卸载时只删除该区块。
- 两个工具都会修改系统配置,请先阅读脚本再执行。
## 目录结构
```text
tools-linux/
├── windiscover/
│ ├── windiscover
│ ├── windows-name-discovery.service
│ ├── windows-name-discovery.timer
│ ├── install.sh
│ ├── uninstall.sh
│ └── README.md
└── winshare/
├── setup-winshare.sh
├── remove-winshare.sh
└── README.md
```
## License
本项目采用 [MIT License](LICENSE)。
Copyright (c) 2026 Tan Shifeng