规范化您软件中公司设备的识别
Normalize Identifying Corporate Devices in Your Software

原始链接: https://lgug2z.com/articles/normalize-identifying-corporate-devices-in-your-software/

此代码提供在macOS和Windows上检测移动设备管理(MDM)注册的功能,可用于识别使用商业许可的潜在公司设备。 macOS函数使用`profiles`命令检查注册状态并提取MDM服务器URL。Windows函数使用`dsregcmd /status`实现相同目的。两者都返回一个布尔值指示注册情况,并可选地返回服务器URL。 作者建议构建一个已知MDM服务器URL的公共存储库,以提高设备识别的准确性,并鼓励用户贡献。他们还推广他们的相关工作——例如“komorebi”之类的软件——并提供指向他们的Bluesky/Mastodon、RSS订阅源、YouTube频道和GitHub赞助的链接,以获取早期访问权限。本质上,这是一个用于许可执行的工具,结合了围绕软件开发的社区建设。

黑客新闻 新 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 规范化识别公司设备在你的软件中 (lgug2z.com) 10 分,Bogdanp 1小时前 | 隐藏 | 过去 | 收藏 | 1 评论 acuozzo 10分钟前 [–] 规范化这个会引发一场猫捉老鼠的游戏,不是吗?回复 考虑申请YC冬季2026批次!申请截止至11月10日 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请YC | 联系 搜索:
相关文章

原文

If you dual-license your software in such a way that it requires a paid license for commercial use, here are two code blobs for you.

pub fn mdm_enrollment() -> eyre::Result<(bool, Option<String>)> {
    let mut command = Command::new("/usr/bin/profiles");
    command.args(["status", "-type", "enrollment"]);
    let stdout = command.output()?.stdout;
    let output = std::str::from_utf8(&stdout)?;
    if output.contains("MDM enrollment: No") {
        return Ok((false, None));
    }

    let mut server = None;

    for line in output.lines() {
        if line.starts_with("MDM server") {
            server = Some(line.trim_start_matches("MDM server: ").to_string())
        }
    }

    Ok((true, server))
}

Windows

pub fn mdm_enrollment() -> eyre::Result<(bool, Option<String>)> {
    let mut command = Command::new("dsregcmd");
    command.args(["/status"]);
    let stdout = command.output()?.stdout;
    let output = std::str::from_utf8(&stdout)?;
    if !output.contains("MdmUrl") {
        return Ok((false, None));
    }

    let mut server = None;

    for line in output.lines() {
        if line.contains("MdmUrl") {
            let line = line.trim().to_string();
            server = Some(line.trim_start_matches("MdmUrl : ").to_string())
        }
    }

    Ok((true, server))
}

Looking at mobile device management (MDM) enrollment is not a silver bullet for identifying corporate devices running your software, but it is a good start.

A productive next step would be to put together a list of known corporate MDM server URLs in a public repository to allow for more granular identification.

This is something anyone with a corporate device enrolled in MDM can contribute to by running profiles status -type enrollment on macOS or dsregcmd /status on Windows.


If you have any questions or comments you can reach out to me on Bluesky and Mastodon.

If you’re interested in what I read to come up with software like komorebi, you can subscribe to my Software Development RSS feed.

If you’d like to watch me writing code while explaining what I’m doing, you can also subscribe to my YouTube channel.

If you would like early access to komorebi for Mac, you can sponsor me on GitHub.

联系我们 contact @ memedata.com