Skip to content
Related Articles

Related Articles

Python program to find IP Address

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 09 Nov, 2017

An IP(Internet Protocol) address is an identifier assigned to each computer and other device(e.g., router, mobile, etc) connected to a TCP/IP network that is used to locate and identify the node in communication with other nodes on the network. IP addresses are usually written and displayed in human-readable notation such as in IPv4(32-bit IP address).
This article focus on How to get IP address of your computer in python.
You have to first import socket library and then use

IP = socket.gethostbyname(hostname) 

and then print the value of the ip into the print() function your IP address as output as shown in the program given below.

# Python Program to Get IP Address
import socket   
hostname = socket.gethostname()   
IPAddr = socket.gethostbyname(hostname)   
print("Your Computer Name is:" + hostname)   
print("Your Computer IP Address is:" + IPAddr)   


Your Computer Name is:pppContainer
Your Computer IP Address is:

Related Post : Java program to find IP address of your computer

This article is contributed by ajay0007. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!