- Python Network Programming - Home
- Python Network Introduction
- Python Networking - Environment Setup
- Python Networking - Internet Protocol
- Python Networking - IP Address
- Python Networking - DNS Lookup
- Python Networking - Routing
- Python Networking - HTTP Requests
- Python Networking - HTTP Response
- Python Networking - HTTP Headers
- Python Networking - Custom HTTP Requests
- Python Networking - Request Status Codes
- Python Networking - HTTP Authentication
- Python Networking - HTTP Data Download
- Python Networking - Connection Re-use
- Python Networking - Network Interface
- Python Networking - Sockets Programming
- Python Networking - HTTP Client
- Python Networking - HTTP Server
- Python Networking - Building URLs
- Python Networking - WebForm Submission
- Python Networking - Databases and SQL
- Python Networking - Telnet
- Python Networking - Email Messages
- Python Networking - SMTP
- Python Networking - POP3
- Python Networking - IMAP
- Python Networking - SSH
- Python Networking - FTP
- Python Networking - SFTP
- Python Networking - Web Servers
- Python Networking - Uploading Data
- Python Networking - Proxy Server
- Python Networking - Directory Listing
- Python Networking - Remote Procedure Call
- Python Networking - RPC JSON Server
- Python Networking - Google Maps
- Python Networking - RSS Feed
Python Network Programming Resources
Python Network - DNS Lookup
The IP addresses when translated to human readable formats or words become known as domain names. The translation of domain names to IP address is managed by the python module dnspython.This module also provides methods to find out CNAME and MX records.
Finding 'A' Record
In the below program we find the ip address for the domain using the dns.resolver method. Usually this mapping between IP address and domain name is also known as 'A' record.
main.py
import dns.resolver
result = dns.resolver.resolve('tutorialspoint.com', 'A')
for ipval in result:
print('IP', ipval.to_text())
Output
When we run the above program, we get the following output −
IP 135.181.223.254
Finding MX Record
A MX record also called mail exchanger record is a resource record in the Domain Name System that specifies a mail server responsible for accepting email messages on behalf of a recipient's domain. It also sets the preference value used to prioritizing mail delivery if multiple mail servers are available. Similar to above programs we can find the value for MX record using the 'MX' parameter in the query method.
main.py
import dns.resolver
result = dns.resolver.resolve('tutorialspoint.com', 'MX')
for exdata in result:
print(' MX Record:', exdata.exchange)
Output
When we run the above program, we get the following output −
MX Record: alt2.aspmx.l.google.com. MX Record: aspmx.l.google.com. MX Record: alt4.aspmx.l.google.com. MX Record: alt3.aspmx.l.google.com. MX Record: alt1.aspmx.l.google.com.
The above is a sample output and not the exact one.