How To Find IP Address In Python

Introduction

 
In this blog, I am going to explain how to find the IP address in Python. It will display the accurate name of the computer and the IP address.
 
What Is an IP Address?
 
An Internet protocol address (IP address) is a numerical label, assigned to each device (e.g., computer, printer) participating in a computer network, which uses the internet protocol for communication.
 
Simple Programming
  1. import socket   
  2. hostname=socket.gethostname()   
  3. IPAddr=socket.gethostbyname(hostname)   
  4. print("Your Computer Name is:"+hostname)   
  5. print("Your Computer IP Address is:"+IPAddr)   
Explanation
 
In this blog, I displayed the name of the computer and the IP address in the Run module.
 
Output
 
==== RESTART: C:/Users/admn/AppData/Local/Programs/Python/Python35/ip.py ====
Your Computer Name is:DESKTOP-L3VQQKN
Your Computer IP Address is:192.168.1.101
>>>