C program to get IP address

In this tutorial you will learn about the C program to get IP address and its application with practical example.

C program to get IP address

In this tutorial, we will learn to create a C program that will get the IP address of computer using C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Array in C Programming.
  • Header Libraries and its usage.

Get IP address

In c programming, it is possible to take or fetch the ip address from the computer and convert it into words or can display in words with the help of a very small amount of code. The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.

Algorithm:-

Program:-

 

Output:-

The above program we have first initialize the required variable.

  • no = it will hold the integer value ip.
  • ifreq = it will hold the interface name in the ifreq structure.
  • ifr = it will hold the address type.
  • array[] = it will hold the integer value for numbers of ip address.

Including the header files required for program

Body of program retrieving the ip address

Main Program

 

 

In this tutorial we have learn about the C program to get IP address and its application with practical example. I hope you will like this tutorial.