Python program to find IP Address

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 192.168.1.35 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.



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)   

chevron_right


Output:

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

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 contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. 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