Graham
Graham

Reputation: 8181

Get the default server in php

When I enter nslookup at the cmd prompt, it tells me the default server.

How do I retrieve that information using PHP?

The server it returns is not the same server that the PHP is running on (or for that matter the nslookup is running on).

I know I could shell out and run nslookup and parse the output, but that doesn't seem very robust (ie. what if the output changes format in future versions of nslookup).

Upvotes: 0

Views: 203

Answers (1)

Dario Eberhard
Dario Eberhard

Reputation: 74

The "Default Server" is your primary DNS server. Getting the default DNS server directly with PHP is not possible. From your further infos after Quentin asked, you dont look for the DNS Name. If it is a Server where you logon with f.ex. Windows, this could be the right answer:

echo getenv("LOGONSERVER");

Otherwise your solution with exec and parsing the output will be the best. Maybe you could use ipconfig /all for that and look for the DNS or DHCP server, depends on your environment.

Upvotes: 1

Related Questions