开发者

how to know 2 lan pc is connetced with my program in php?

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.


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.


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.


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);
    }

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜