C Program to Display Hostname And IP Address

Prem Tiwari - - 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:

About: Prem Tiwari

Prem Tiwari is the founder of FreeWebMentor.com and also 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.

Tags: , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.