General discussion


PHP retrieve remote domain

By luschen1611 ·
Is there a way to find the domain name that the remote computer is connected to? This is for an authentication setup to allow access for a specific network. I have tried exec("ipconfig 2&>1", $output) and shell_exec("ipconfig /all") but it doesn't give me what I need for 2 reasons: 1. it doesn't have all the information, including the domain name 2. it retrieves the information from the server, not the remote computer.

Any suggestions?


This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by Jaqui In reply to PHP retrieve remote domai ... - - [04/Sep/2005:11:24:46 -0700] "GET /testing/ HTTP/1.1" 200 519

from server logs.

then use tracert to get the remote host domain.

if using apache, you have runtime variable of remote host available.

Collapse -

by Jaqui In reply to

tracert output for techrepublic from neigbours computer.
seems to me it includes the host domain data you are looking for.

#6 27 ms 20 ms 21 ms []

#7 33 ms 15 ms 17 ms []

#8 31 ms 40 ms 37 ms []

#9 32 ms 31 ms 40 ms []

#10 42 ms 37 ms 52 ms []

#11 221 ms 195 ms 201 ms []

#12 33 ms 37 ms 140 ms []

#13 39 ms 33 ms 35 ms []

#14 46 ms 34 ms 41 ms []

#15 34 ms 51 ms 36 ms []

Collapse -

by Toivo Talikka In reply to PHP retrieve remote domai ...

Try this, wrapped in HTML:

$ip_address = $_SERVER['REMOTE_ADDR'];
$host_name = $_SERVER['REMOTE_HOST'];

echo "<p>ip address = $ip_address</p>";
echo "<p>hostname = $host_name</p>";

REMOTE_HOST is the Host name from which the user is viewing the current page. The reverse DNS lookup is based on the REMOTE_ADDR of the user.

In Apache you need to have 'HostnameLookups On' inside httpd.conf for the variable REMOTE_HOST to exist. This will generate at least one DNS lookup to the name servers for every HTTP request. You may be better off by relying on the IP address instead.

I have not tried these functions from outside the LAN but you can test inside your LAN if you add the IP address and the hostname of your workstation to the hosts file of your web server:

Collapse -

by luschen1611 In reply to PHP retrieve remote domai ...

I think you are misunderstanding what I want. I'm not looking for the internet DNS hostname (i.e. What I want is the name of the network the computer is connected to on a LAN. To find this on WinXP/W2k, etc. go to Start\Run\Cmd and hit Ok...type "ipconfig" and enter. The answer to the row titled "Connection-specific DNS Suffix" is what I'm looking for. Can also find it from Control Panel\System\Computer Name and it is the entry for "Domain".

Thanks for your answers though.

Collapse -

by Toivo Talikka In reply to PHP retrieve remote domai ...


Is the web server which runs PHP part of your intranet?

If your web server is accessible to users from the internet, even if you could extract the domain information somehow from the remote client, would you trust that information? If it can be falsified, it will.

My guess is that you will have to use PHP to push some Javascript or Vbscript to the remote client and take it from there.

If the authentication of remote users is the purpose of this exercise, have you checked out what you could do with digital certificates?

Collapse -

by luschen1611 In reply to PHP retrieve remote domai ...

No, I haven't checked into digital certificates. This isn't for any kind of sensitive data (personal info, financial info, etc.). It is just for a library's database that is to be used for Mission Support only (Air Force library), hence restricted to a certain network.

Yes, the server is on an intranet, which is a different one from the one I need to allow access to. It is a WinNT (full patches, etc.) server using IIS.

We don't have any money for setting up a SSL certification process. Is there a no-cost approach to this? I have looked at OpenSSL before but didn't get it working....was just playing with it at the time. Would this do want I want? Would it cost something to get a good certificate to use? Would the certificate have to be installed on the client's computer by the client himself, or would it be done remotely from the server?

Thanks for helping me on this.

Collapse -

by grtammi In reply to PHP retrieve remote domai ...

Try this .... I think it's what you're looking for.


$dns = getDomainSuffix() ;

if ($dns)
echo "Your DNS suffix is: " .$dns ;
echo "could not find DNS suffix." ;

function getDomainSuffix(){

// Setup the command to run from "run"
$cmd = "ipconfig /all > ipsettings.txt";

// Make a new instance of the COM object
$shell = new COM("WScript.Shell");

// Make the command window but dont show it.
$myExec = $shell->Run($cmd, 0, true);

# open file
$fp = file("ipsettings.txt") ;

# check array for Connection-specific DNS Suffix

for($i=0;$i<count($fp);$i++) {
if (strpos($fp[$i], "Connection-specific DNS Suffix ")) {
# found the dns suffix - split on the : and display
$dns = split(":", $fp[$i]) ;
return $dns[1] ;

# still here? nothing found, return false
return false ;



Collapse -

by luschen1611 In reply to

Thanks for your help gtammi. You were closest by far. The script didn't provide any data for me nor gave me an error, but that is ok because I have moved on since that point. Thanks for your help.

Collapse -

by grtammi In reply to PHP retrieve remote domai ...

Couple more things ... should probably try to delete ipsettings.txt after you're done with it, and if you doubt the validity of the file, just use a print_r($fp) after opening the file - you'll see that the data in the file matches an ipconfig /all from the command prompt.

Collapse -

by luschen1611 In reply to PHP retrieve remote domai ...

This question was closed by the author

Back to Web Development Forum
10 total posts (Page 1 of 1)  

Related Discussions

Related Forums