深度阅读

How to get remote DNS information using Python

作者
作者
2023年08月22日
更新时间
7.5 分钟
阅读时间
0
阅读量

To get remote DNS information using Python, you can use the socket module. Here’s an example of how to get the IP address of a domain name using socket.getaddrinfo():

import socket

# Set the domain name
domain_name = "example.com"

# Get the IP address for the domain name
results = socket.getaddrinfo(domain_name, None)

# Print all IP addresses for the domain name
for result in results:
    print(result[4][0])

In this example, we use the socket.getaddrinfo() function to get the IP address of example.com. The getaddrinfo() function returns a list of tuples, each of which contains information about a single address for the specified domain name. We iterate over this list and print each IP address using tuple indexing.

相关标签

博客作者

热爱技术,乐于分享,持续学习。专注于Web开发、系统架构设计和人工智能领域。