0

i tried to get current system domain ip address using c++ win32 API.

How Can i Achieve this?

Arjun babu
  • 607
  • 2
  • 13
  • 42

2 Answers2

2

If you mean a way to get your public ip behind a NAT, you have to open a socket, bind it and connect to a server and request it to answer you what your ip is. not an easy task. If you only want to know your private ip, you can read this thread on stackoverflow : Get the IP Address of local computer

Community
  • 1
  • 1
geekpp
  • 511
  • 2
  • 6
  • @ geekpp : i am not asking my system ip,i am asking domain(dns) ip..i mean if my system has in a "aaa" domain,how to i get that dns ip address? – Arjun babu Nov 16 '12 at 13:00
0

If you mean the IP address(es) of your local system's DNS server(s), you could execute ipconfig /all and parse the output for it/them.

mark
  • 5,269
  • 2
  • 21
  • 34
  • 1
    You can get it from the registry using the registry APIs... `HKEY_LOCAL_MACHINE` and `SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces` look for `NameServer` and `DhcpNameServer` – mark Nov 16 '12 at 13:16
  • @ Mark : Each system have different key value interfaces.ex:`...\Interfaces\{0BDB7A0B-8FC4-4C3C-86CE-33D1616B345D}` and `\Interfaces\{603cd2ff-D9F7-49DC-898E-06D1616B345D}`.how can i achieve commonly? – Arjun babu Nov 16 '12 at 13:29
  • 1
    Yes, indeed... after you `RegOpenKeyEx`, you enumerate them with `RegEnumKeyEx`. For each, `RegOpenKeyEx` then `RegQueryValueEx` for the server addresses. – mark Nov 16 '12 at 13:33
  • How do i know,which key has a value? – Arjun babu Nov 16 '12 at 13:39
  • 1
    The query will fail if there's no value, check like this: `if ( ERROR_SUCCESS == RegQueryValueEx( key, "NameServer", 0, &type, (unsigned char*)keyname, &namelen ) ) {...` – mark Nov 16 '12 at 13:48
  • u cant get my point Mark.In interface key,have 5 subkeys like `{0BDB7A0B-8FC4-4C3C-86CE-33D1616B345D}`and `{603cd2ff-D9F7-49DC-898E-06D1616B345D}`etc.how can i know which key have a Nameserver address? – Arjun babu Nov 16 '12 at 13:53
  • enumerate them and look in each – mark Nov 16 '12 at 14:00