MX记录查找和检查

发布于 2024-10-05 11:11:05 字数 353 浏览 4 评论 0原文

我需要创建一个工具来检查域的实时 mx 记录是否符合预期(我们的一些员工在摆弄这些记录时遇到了问题,导致所有传入的邮件都被重定向到空白)

现在我不会撒谎,我根本不是一个称职的程序员!我已经阅读了大约 40 页的“深入 Python”,可以阅读和理解最基本的代码。但我愿意学习,而不仅仅是得到答案。

那么有人能建议我应该使用哪种语言吗?

我正在考虑使用 python 并从使用 0s.system() 的方式开始执行 (dig +nocmd domain.com mx +noall +answer) 来提取记录,然后我对如何进行有点困惑将其与现有的记录集进行比较。

抱歉,如果这一切听起来像是废话!

谢谢 克里斯

I need to create a tool that will check a domains live mx records against what should be expected (we have had issues with some of our staff fiddling with them and causing all incoming mail to redirected into the void)

Now I won't lie, I'm not a competent programmer in the slightest! I'm about 40 pages into "dive into python" and can read and understand the most basic code. But I'm willing to learn rather than just being given an answer.

So would anyone be able to suggest which language I should be using?

I was thinking of using python and starting with something along the lines of using 0s.system() to do a (dig +nocmd domain.com mx +noall +answer) to pull up the records, I then get a bit confused about how to compare this to a existing set of records.

Sorry if that all sounds like nonsense!

Thanks
Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

赢得她心 2024-10-12 11:11:06

使用 dnspython 模块(不是内置的,您必须 pip install 它):

>>> import dns.resolver
>>> domain = 'hotmail.com'
>>> for x in dns.resolver.resolve(domain, 'MX'):
...     print(x.to_text())
...
5 mx3.hotmail.com.
5 mx4.hotmail.com.
5 mx1.hotmail.com.
5 mx2.hotmail.com.

With dnspython module (not built-in, you must pip install it):

>>> import dns.resolver
>>> domain = 'hotmail.com'
>>> for x in dns.resolver.resolve(domain, 'MX'):
...     print(x.to_text())
...
5 mx3.hotmail.com.
5 mx4.hotmail.com.
5 mx1.hotmail.com.
5 mx2.hotmail.com.
治碍 2024-10-12 11:11:06

看一下dnspython,这个模块应该可以很好地为您进行查找,而无需诉诸系统调用。

Take a look at dnspython, a module that should do the lookups for you just fine without needing to resort to system calls.

貪欢 2024-10-12 11:11:06

上述解决方案是正确的。有些东西我想添加和更新。

  • dnspython 已更新为可与 python3 一起使用,并且它已取代 dnspython3 库,因此建议在
  • 域< 中使用 dnspython /strong> 将严格接受,仅此而已。

例如:dnspython.org是有效域名,而不是www.dnspython.org

如果您想获取某个域的邮件服务器,这里有一个函数。

def get_mx_server(domain: str = "dnspython.org") -> str:
    mail_servers = resolver.resolve(domain, 'MX')
    mail_servers = list(set([data.exchange.to_text()
                             for data in mail_servers]))
    return ",".join(mail_servers)

the above solutions are correct. some things I would like to add and update.

  • the dnspython has been updated to be used with python3 and it has superseeded the dnspython3 library so use of dnspython is recommended
  • the domain will strictly take in the domain and nothing else.

for example: dnspython.org is valid domain, not www.dnspython.org

here's a function if you want to get the mail servers for a domain.

def get_mx_server(domain: str = "dnspython.org") -> str:
    mail_servers = resolver.resolve(domain, 'MX')
    mail_servers = list(set([data.exchange.to_text()
                             for data in mail_servers]))
    return ",".join(mail_servers)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文