There are many ways to find Hostname and IP address of a local machine. Here is a simple method to find hostname and IP address using C program.
We will be using the following functions :-
gethostname() : The gethostname function retrieves the standard host name for the local computer.
gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.
inet_ntoa() : The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.
Hostname: cContainer Host IP: 10.98.162.101
Output varies machine to machine
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Program to validate an IP address
- Java program to find IP address of your computer
- C Program to find IP Address, Subnet Mask & Default Gateway
- Program to determine class, Network and Host ID of an IPv4 address
- Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
- C program to display month by month calendar for a given year
- Difference between MAC Address and IP Address
- Finding DBA from given IP address
- Address of a function in C or C++
- Network Address Translation (NAT)
- Finding IP address of a URL in Java
- Alias/Secondary IP Address
- Compression of IPv6 address
- Extracting MAC address using Python
- Address Resolution in DNS (Domain Name Server)
- Transition from IPv4 to IPv6 address
- Types of Network Address Translation (NAT)
- Local Broadcast and Loopback Address
- How Address Resolution Protocol (ARP) works?
- Alternate method to find DBA from given IP address
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.