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.
# 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) |
Output:
Your Computer Name is:pppContainer Your Computer IP Address is:10.98.162.168
Last Updated on December 29, 2021 by admin