IP (Internet Protocol) Address is an address of your network hardware. It helps in connecting your computer to other devices on your network and all over the world. An IP Address is made up of numbers or characters combined by ‘.’ symbol.
Example: It is an example of IP address.
All devices that are connected to an internet connection have a unique IP address which literally gives the idea that a large number of IP addresses had to be created for every system.
Local IP address: It is the IP address of your computer system which is meant to be kept private and thus is also known as private IP addresses. This article focuses on how to extract the IP address. A private IP address is the address of your device connected to the home or business network. If you have a few different devices connected to one ISP (Internet Service Provider), then all your devices will have a unique private IP address. This IP address cannot be accessed from devices outside your home or business network. Private IP addresses are not unique because there is a limited number of devices on your network. There are some other types of IP addresses that exist like, public IP addresses, static IP addresses and dynamic IP addresses that follow the same format for representation.
IPv4 address: The IPv4 version used to configure IP addresses in numerical value and it uses the hexadecimal number system to complete its job i.e. what makes it possible to get millions of IP, different for every system.
Example: In this example, we are trying to get the local IP address without using terminal and its commands. Instead, we are using a PHP program to get the same job done. We will be required two methods that are mentioned below:
- getHostByName() Function: It gets the IPv4 address corresponding to a given Internet host name.
- getHostName() Function: It gets the standard host name for the local machine.
- Program: Here, first we get the name of the local machine as the string and then by using that we will get the corresponding address to that name.
// Declaring a variable to hold the IP
// address getHostName() gets the name
// of the local machine getHostByName()
// gets the corresponding IP
// Displaying the address
The fact that no output is provided with this program because of security reasons. Sharing of IP addresses can lead to security breaches and one should be careful not to share it. Any unethical access can cost you theft of personal space and even identity.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.