C Program to Display Hostname And IP Address

| Last Updated: | In: C Programming Tutorial


In this program, we will share how to get the Hostname and IP address of a local machine. In this program, I am using these predefined functions:

1) gethostname(): Get the hostname of a local machine.
2) gethostbyname(): Get the host information corresponding to the hostname.
3) inet_ntoa(): This function will convert an (Ipv4) Internet network address into an ASCII string in decimal format.

C Program to display hostname and IP address

Copy the below c program and execute it with the help of c compiler.

Output of program:

Hostname: cContainer
Host IP: 10.98.162.101


About: Prem Tiwari

Prem Tiwari is the founder of freewebmentor.com and is a professional developer who has vast experience in PHP and open source technologies. Apart from this, he is a blogger by hobby and also he has been a regular speaker of WordPress sessions in various IT Companies.


You may also like:

Tags: , , , , ,