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:
- ChatGPT vs DeepSeek: Who is the winner?Here’s a detailed comparison between ChatGPT (specifically GPT-4o) and DeepSeek-V3 based on various online resources, focusing on key metrics such as time to build, cost, performance, and other relevant factors: 1. Architecture and Model Size 2. Training Cost and Efficiency 3. Performance Benchmarks 4. Cost of Usage 5. Open-Source and Accessibility 6. Real-World Applications 7….
- People are becoming AI Engineer with this free course in 2025: Here is how to join this…Artificial Intelligence (AI) has become a cornerstone of technological advancement, shaping industries and transforming careers. If you’ve been looking to upskill or dive into the fascinating world of AI, freeCodeCamp.org has released an incredible resource: the AI Foundations Course on YouTube. This 11-hour video, created by @LunarTech_ai, is not just another crash course – it’s…
- Apply to Google’s Student Training in Engineering Program (STEP) Intern, 2025Google’s Student Training in Engineering Program (STEP) Intern, 2025, is a fantastic opportunity for students passionate about programming and software development. Designed to support skill-building and career growth, this program offers a chance to work with one of the world’s leading tech companies. Here’s everything you need to know about this internship opportunity. What Is…
- Self-Driving Car Saves Falling Pedestrian, Showcases Promise of Autonomous TechnologyIn a dramatic demonstration of the potential for self-driving technology to enhance road safety, a Waymo’s autonomous vehicle recently avoided a serious accident when a scooter rider, startled by a pothole, lost balance and fell onto the road. The incident, captured on video, highlights the advanced capabilities of modern driverless technology. As the rider tumbled…
- Instant Karma: Employer Fires Tech Team with AI, Faces Backlash on LinkedIn While Seeking New DevelopersIn a bold—and controversial—move, Canadian software developer Wes Winder has sparked heated online debates after replacing his entire development team with Artificial Intelligence (AI). Winder, who took to LinkedIn to announce his decision, has been met with a wave of criticism and ridicule, with many questioning the practicality and ethics of his approach. The Controversial…