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: 10.98.162.101

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: , , , , ,

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.

Solved Programs