1

Possible Duplicate:
get global ip address

I am wondering is there anyway to get the ipv4 address easily?

Community
  • 1
  • 1
user705414
  • 20,472
  • 39
  • 112
  • 155

4 Answers4

2

For the local computer:

Get the IP address of the machine

Community
  • 1
  • 1
Brian Webster
  • 30,033
  • 48
  • 152
  • 225
1

It depends on the OS your program running on.

For Windows see http://msdn.microsoft.com/en-us/library/aa365915%28v=VS.85%29.aspx

0

Try Beej's Guide to Network Programming at http://beej.us/guide/bgnet/

There you may find an answer for your platform and the case of multiple addresses.

Mario
  • 529
  • 7
  • 19
0

Actually C++ standard library does not provide any function to get the ip address of a system. The api for that must be provided by the OS on which you are working.

From your question what I understood is you are working on something but your IP keep changing because it is assigned by DHCP, well I may be wrong.

However, for linux you would like to google for inet_ntop

Check this out:
#include <arpa/inet.h>
const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);

Mayank
  • 5,454
  • 9
  • 37
  • 60