Page 1 of 1

[SOLVED] Get Computer Name. Like I get HOST, IP, etc.

Posted: Fri Sep 10, 2004 11:06 pm
by drale
I would like to now what variable or function to use to get the computer name of the computer visiting a page. This is when another computer on my network visits a page on my server I can see the computer name instead of just the IP.

Ive tried. the following dif variables.

Code: Select all

$_SERVERї'REMOTE_PORT'];
$_SERVERї'REMOTE_ADDR'];
Or do I need to get the IP "192.168.0.#" then somehow trace what computer name it is. I know this can be done on a page becuase my router detects IPs and computer names in its settings. If I cant do it in PHP what can I do?

Posted: Fri Sep 10, 2004 11:59 pm
by feyd
you can't.

Posted: Sat Sep 11, 2004 1:58 am
by drale
Nevermind I got it.

Code: Select all

<?php
$nbtstat = "nbtstat -A ".$REMOTE_ADDR;
exec ($nbtstat,$result);
foreach ($result as $row)
&#123;
    if (strpos($row,"<20>"))
    &#123;
        $pcname = strtok($row," ");
    &#125;

    if (strpos($row,"<03>"))
    &#123;
        $login = strtok($row," ");
    &#125;

    if (strpos($row,"<1D>"))
    &#123;
        $workgrp = strtok($row," ");
    &#125;
&#125;

print ("PC NAME: $pcname<BR> LOGIN NAME: $login<BR> WORKGROUP:$workgrp<BR> IP: $REMOTE_ADDR<BR> ");



?>
Gives me:

Code: Select all

PC NAME: (my pc name)
LOGIN NAME: (my login name)
WORKGROUP: WORKGROUP
IP: 192.168.0.3
And I understand why too.

Posted: Sat Sep 11, 2004 2:47 pm
by AngusL
You can use nbtstat in PHP? interesting.

Posted: Sat Sep 11, 2004 3:01 pm
by Weirdan
AngusL wrote:You can use nbtstat in PHP? interesting.
you can run any executable via [php_man]exec[/php_man] (depending on the permissions set for executable in question, of course).