Find IP Address C Program

C Program To Find IP Address in Windows and Linux

Learn How To Find IP Address in C Programming. This IP Address C Program works in both Linux and Windows operating systems for both localhost server or any web server. IP stands for Internet Protocol.

This C Program To Find Localhost IP Address takes in an input string. It can be either your localhost or any website address. The IP address of your localhost server will generally be 127.0.0.1.

However, you should be connected to the internet if you need to find out the IP Address of any website. If it’s your localhost, then internet connection is not mandatory.

Must Read: C Program To List Names of all Files in a Directory

inet_ntoa(*ipaddress[count]): The function inet_ntoa() converts a network address (such as localhost or any web server like www.fb.com) to an actual IP Address consisting of numbers using struct in_addr.


herror(): The function herror() helps to display the error code and description if the name lookup terminates abnormally or if it cannot find the IP address.

C Program To Find IP Address in Linux Ubuntu

Must Read: C Program To Shutdown Linux Operating System

C Program To Get IP Address in Windows Operating System

Output

C Program To Find IP Address in Linux and Windows

If you have any doubts or compilation errors in this code to get Local IP Address in C programming, let us know about it in the comment section below.


Tushar Soni

I am Tushar Soni, Co - Founder of CodingAlpha. I am a computer science student from India and passionate about Web Development and Programming. Connect with me on Facebook | LinkedIn | Google Plus

2 thoughts on “Find IP Address C Program

  • October 20, 2016 at 8:22 pm
    Permalink

    Thanks for this program. After so many searches, where I was getting only localhost ip address c program, finally I got the actual ip address code.

    Reply
  • October 21, 2016 at 1:47 am
    Permalink

    for a standard conforming program you have to declare main as “int main(int argc, char **argv)”. please note that f() is a k&r definition and something different than f(void).

    Reply

Join The Discussion