dnspython模块报错 AttributeError: 'CNAME' object has no attribute 'address'
2024-10-19 20:45:54
有时候用到这个模块的时候会报错
AttributeError: 'CNAME' object has no attribute 'address'
如下所示
[root@ansible ch01]# ./dnspython_ex1.py
Please input a domain: www.baidu.com
Traceback (most recent call last):
File "./dnspython_ex1.py", line 9, in <module>
print(j.address)
AttributeError: 'CNAME' object has no attribute 'address'
代码是这样的:
#!/usr/bin/env python
import dns.resolver
domain = raw_input('Please input a domain: ')
A = dns.resolver.query(domain, 'A')
for i in A.response.answer:
for j in i.items:
print j.address
我们只需在最后需要输出address时在前面增加if判断
if j.rdtype == 1:
将代码修改如下:
#!/usr/bin/env python
import dns.resolver
domain = raw_input('Please input a domain: ')
A = dns.resolver.query(domain, 'A')
for i in A.response.answer:
for j in i.items:
if j.rdtype == 1:
print j.address
运行就不会报错了
[root@ansible ch01]# ./dnspython_ex1.py
Please input a domain: www.baidu.com
14.215.177.38
14.215.177.39
最新文章
- 开始用Word 2013来写博客
- Endnote专题之--output style相关问题
- [Java]Hessian客户端和服务端代码例子
- SQL 笔记
- Linux chkconfig命令
- Eclipse的java代码出错:The import org.apache cannot be resolved
- LinkCode 第k个排列
- THINKPHP 3.2 PHP SFTP上传下载 代码实现方法
- Django 学习笔记(三)模板导入
- C语言学生信息管理系统项目源码
- 安卓高级6 CoordinatorLayout
- 《AutoCAD Civil 3D .NET二次开发》勘误2
- java中变量的存储位置
- 转:python request属性及方法说明
- SpringBoot下如何配置实现跨域请求?
- C语言复习:指针知识
- mysql 记录的增删改查
- android--Git上克隆项目遇到的坑
- junit所需要的jar包
- 20155331 2016-2017-2 《Java程序设计》第10周学习总结