You are here

C program to get IP address

C program to print IP (Internet Protocol) address of your computer, system function is used to execute the command "ipconfig" which prints IP address, subnet mask, and default gateway. The code given below works for Windows XP and Windows 7. If you are using Turbo C compiler then execute this program from the folder, it may not work when you are working in a compiler and trying to run it by Ctrl + F9.

C programming code

#include<stdlib.h>
 
int main()
{
   system("C:\\Windows\\System32\\ipconfig");
 
   return 0;
}

Download IP address program.

Output of program: (In Windows 7)
IP address C program output

Only a part of the output is shown in the image.