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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
drale
Forum Newbie
Posts: 8
Joined: Fri Sep 10, 2004 2:43 am

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

Post 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?
Last edited by drale on Sat Sep 11, 2004 1:59 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you can't.
drale
Forum Newbie
Posts: 8
Joined: Fri Sep 10, 2004 2:43 am

Post 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.
AngusL
Forum Contributor
Posts: 155
Joined: Fri Aug 20, 2004 4:28 am
Location: Falkirk, Scotland

Post by AngusL »

You can use nbtstat in PHP? interesting.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post 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).
Post Reply