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:
- Imagination to Reality, Unlocking the Future: Genesis Physics Engine for 4D SimulationGenesis has unveiled a groundbreaking physics engine capable of generating immersive 4D dynamical and physical worlds. It sets new benchmarks in areas such as: All this comes with optimized performance, making it an essential tool for researchers, developers, and hobbyists alike. Open-Source and Free for All The Genesis physics engine is completely open-source and free….
- Simple Code to compare Speed of Python, Java, and C++?Introduction There’s often a lot of debate about the speed of different programming languages, with many assuming that C++ is always the fastest and Python is the slowest. However, it’s not as straightforward as it seems. In this article, I’ll walk you through simple programs with the same logic written in Python, Java, and C++…
- Falling Stars Animation on Python.Hub October 2024Hello Python enthusiasts! Check out the cool animation below, featured on our Instagram page, python.hub. You can view the latest reel, posted on October 8, 2024, showcasing this animation. View this post on Instagram A post shared by Lalit Tomar • AI & Coding Wizard (@python.hub) Want the code for this reel? Simply follow this…
- Most Underrated Database Trick | Life-Saving SQL CommandHello folks! Today we are again back with a super important article on the Most underrated SQL & Database Trick to save your entire application. Maintaining the data integrity of your application is very important in this world of software development. However, even experienced engineers may encounter situations where mistakes happen in changing or updating…
- Python List MethodsHello friends, in this article, we will explore various Python List methods, indispensable tools in a programmer’s toolkit for manipulating lists efficiently. List methods in Python are built-in functions designed to perform specific tasks when applied to lists. To access a method in Python, we simply use the dot notation (.), linking the method to…