Simple Python Program To Find IP Address

What is an Ip Address?
An Internet Protocol address (Ip 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 othe…


This content originally appeared on DEV Community and was authored by WhiteHat💫

What is an Ip Address?
An Internet Protocol address (Ip 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 format such as 192.168.55.10 in IPv4(32-bit IP address). Addresses in IPv4 are 32-bits long. This allows for a maximum of 4,294,967,296 (232) unique addresses. Addresses in IPv6 are 128-bits, which allows for 3.4 x 1038 (2128) unique addresses. In this article we will focus on how to get the Ip address of your computer in python. First of, you will have to import the python socket library and proceed to use this "IP=socket.gethostbyname(hostname)" then you print the value of the ip into the print() function in you code, the output of your IP address would be displayed as shown in the program below:

"""Python program to find 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: mycomputer
Your Computer IP Address is:192.168.40.109

Conclusion
With python, there are lots of programs you can write and explore, this is just one of many of them. Get hands on with this simple script and see your results. And that's it! If you have any suggestions or questions for improvements please let me know in the replies below 😁


This content originally appeared on DEV Community and was authored by WhiteHat💫


Print Share Comment Cite Upload Translate Updates
APA

WhiteHat💫 | Sciencx (2021-11-29T09:08:34+00:00) Simple Python Program To Find IP Address. Retrieved from https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/

MLA
" » Simple Python Program To Find IP Address." WhiteHat💫 | Sciencx - Monday November 29, 2021, https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/
HARVARD
WhiteHat💫 | Sciencx Monday November 29, 2021 » Simple Python Program To Find IP Address., viewed ,<https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/>
VANCOUVER
WhiteHat💫 | Sciencx - » Simple Python Program To Find IP Address. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/
CHICAGO
" » Simple Python Program To Find IP Address." WhiteHat💫 | Sciencx - Accessed . https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/
IEEE
" » Simple Python Program To Find IP Address." WhiteHat💫 | Sciencx [Online]. Available: https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/. [Accessed: ]
rf:citation
» Simple Python Program To Find IP Address | WhiteHat💫 | Sciencx | https://www.scien.cx/2021/11/29/simple-python-program-to-find-ip-address/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.