Get IP address using Python

Get IP address using Python

An IP address is a label that is used to identify one or more devices on a computer network, such as the internet. And today we will learn how to get an IP address using Python. It is comparable to a postal address. An IP address is a long number written in binary

Today we will learn how to find the IP address of the machine we are working on. We will use the socket module which provides access to the BSD socket interface. This is available on all modern operating systems like Unix systems, Windows, MacOS, and probably additional platforms.



So let’s see and understand the code


Code

# importing socket module
import socket 

# getting machine name
hostname = socket.gethostname() 

# getting IP Address
IPAddr = socket.gethostbyname(hostname) 

# printing hostname
print("Your Computer Name is:" + hostname) 

# printing IP Address
print("Your Computer IP Address is:" + IPAddr) 

Output



Your Computer Name is: LAPTOP-HAHA2FDA
Your Computer IP Address is:192.168.12.324


Run Python Code


Thanks for reading


Keep updated for more content like this


Also read:


  • Viral Moment: China’s AgiBot X2 Makes History With World’s First Webster Backflip
    The news AgiBot’s humanoid X2 just stuck what the company calls the world’s first seamless Webster backflip by a robot, a tightly executed acrobatic front-flip variation more common in parkour than in labs, according to posts circulating on X and robotics channels this week. The clip shows the X2 gathering momentum, swinging through, and cleanly…
  • Terminator Rising: Albania Hands Power to AI, Echoing a Nightmare of Human Extinction
    Imagine a world where your smart home assistant doesn’t just turn on the lights—it decides you’re a threat and locks you in. That’s the chilling reality Albania just cracked open by appointing Diella, an AI “minister,” to control government decisions. This isn’t some distant sci-fi plot; it’s happening now, in 2025, and it echoes the…
  • What Is Albania’s World-First AI-Generated Minister and How Does It Work?
    Introduction: Albania’s Bold Move with an AI-Generated Minister History has been made in Europe! Albania has just sworn in the world’s first AI-generated minister — and the internet can’t stop talking about it. Meet Diella, a digital “politician” designed by Prime Minister Edi Rama to fight corruption and manage public tenders with zero human bias….
  • Does ChatGPT believe in God? ChatGPT’s Personal Opinion
    Introduction Since the launch of ChatGPT, users have asked it all kinds of interesting, funny, and even thought-provoking questions. Recently, one user asked ChatGPT to share its personal opinion on the existence of God — without relying on references from religious texts like the Gita, Quran, or Bible. Instead, the request was for a purely…
  • ChatGPT vs Human: The Breath-Holding Chat That Ends in “System Failure”
    People experiment with ChatGPT in countless ways every day. While many rely on ChatGPT and other AI tools for productivity and work, others turn to it purely for fun. Almost daily, new entertaining and funny conversations with ChatGPT surface online, and one such chat is currently going viral on social media. This particular exchange is…


Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you

Related Articles