tags:

views:

31

answers:

3

I have 4 PCs which are connected through the LAN. I am making a PHP program that will differentiate each PC separately and i will keep each pc record.

But when i am getting an IP address i am getting same IP for all. I guess i should retrieve MAC address for all pcs separately, but i don't know how will i fetch MAC address.

I am using Linux OS.

Programing tips will be appreciated.

A: 

As far as I know, you cannot do this with PHP alone. However, if you have exec() rights on the server, the you might be able to use:

arp -a ipaddress

Where ipaddress is the IP address of the computer on your LAN. You would need to use something like regex to seperate the MAC address from the rest of the output.

Joseph Redfern
I have to keep each performance of pc through LAN or single PC.I am guessing "http" header keeps all each pc differentiating.If i will parse "http" then i may know which is being access my program. is this right ?
Ajay_kumar
The MAC address of the computer is specific to the network card of the computer, whereas the IP address is not. You can differentiate between one machine and another by comparing their MAC addresses. Unless I am mis-understanding your question, I don't think you need to go into the realm of HTTP Headers (as pinging and ARP requests do not involve HTTP Headers). HTTP Headers do not contain the MAC addresses.
Joseph Redfern
A: 

PEAR’s Net_Ping is a niffty wrapper class for executing ping calls from PHP. You can use it to check if a remote server is responding correctly. The library can be download from here.

pear install Net_Ping-2.4.4




<?php

    require_once "Net/Ping.php";

    $ping = Net_Ping::factory();

    if(PEAR::isError($ping))
      echo $ping->getMessage();
    else
    {
      /* Number of packets to send */
      $ping->setArgs(array('count' => 4));
      $rawData = $ping->ping('google.com');
      print_r($rawData);
    }

?>
Sudantha
some related file is not there like Pear.php.
Ajay_kumar
i believe that its OS in-depended , Please check the pear documentation http://pear.php.net/manual/
Sudantha
A: 

I don't think that the mac-adress is included in the http-header. So it is probably hard to get it via php. I think you're better off trying to fix the ip-issue. Sorry I can't help you more.

Edit: Actually... searching around a little I found a possible solution:

$mac = `ping -c 1 $ip && arp -a | grep $ip`

You probably have to parse the output though. I get: xxx.xxx.local (192.168.0.10) at d5:c2:c3:13:a2:b1 [ether] on eth0

When doing arp -a 192.168.0.10

Edit: Like the post under states, you would need exec-rights.

Edit: Sorry, just realized that in order for this to work, you would need the ip... Which you don't have.

refuser