C Program to Display Hostname And IP Address

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:

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Prem Tiwari

An engineer by profession and a passionate blogger by heart. Founder of FreeWebMentor.com (A Programming blog for beginners), Tech Speaker at various forums. A part from this he is an open source enthusiast, WordPress Lover, Blogger, SEO, and Growth Strategic.

Article Tags: , , , , ,