GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • Learn Python
  • Python Tutorial
  • Basics
  • Lists
  • Dictionary
  • Code Snippets
  • Comments
  • Modules
  • API
  • Beautiful Soup
  • Cheatsheet
  • Games
  • Loops

This view

  • Original page
  • New address

GeezerVison is showing www.pythonforbeginners.com — DNS Lookup With Python - PythonForBeginners.com

You are here: Home / Code Snippets / DNS Lookup With Python

The sockets module provides an easy way to look up a host name’s ip address.


import socket

addr1 = socket.gethostbyname('google.com')
addr2 = socket.gethostbyname('yahoo.com')

print(addr1, addr2)

Which will output the following ip addresses:


173.194.121.9 98.138.253.109

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Enroll Now

More Python Topics

API Argv Basics Beautiful Soup Cheatsheet Code Code Snippets Command Line Comments Concatenation crawler Data Structures Data Types deque Development Dictionary Dictionary Data Structure In Python Error Handling Exceptions Filehandling Files formatting Functions Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pip Pyspark Python Python On The Web Python Strings Queue Requests Scripts Split Strings System & OS urllib2
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.