472,330 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,330 software developers and data experts.

getting mac address of client machines

pradeepjain
563 512MB
Hii,
I need to know is there any way to get the mac id's of the machines accessing ma site! I want to make a access lock using the mac id's
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function returnmacaddress() {
  3. // This code is under the GNU Public Licence
  4. // Written by michael_stankiewicz {don't spam} at yahoo {no spam} dot com
  5. // Tested only on linux, please report bugs
  6.  
  7. // WARNING: the commands 'which' and 'arp' should be executable
  8. // by the apache user; on most linux boxes the default configuration
  9. // should work fine
  10.  
  11. // get the arp executable path
  12. $location = 'which arp';
  13. $location = rtrim($location);
  14. // Execute the arp command and store the output in $arpTable
  15. $arpTable = '$location -n';
  16. // Split the output so every line is an entry of the $arpSplitted array
  17. $arpSplitted = split("\n",$arpTable);
  18. // get the remote ip address (the ip address of the client, the browser)
  19. $remoteIp = $_SERVER['REMOTE_ADDR'];
  20. $remoteIp = str_replace(".", "\\.", $remoteIp);
  21. // Cicle the array to find the match with the remote ip address
  22. foreach ($arpSplitted as $value) {
  23. // Split every arp line, this is done in case the format of the arp
  24. // command output is a bit different than expected
  25. $valueSplitted = split(" ",$value);
  26. foreach ($valueSplitted as $spLine) {
  27. if (preg_match("/$remoteIp/",$spLine)) {
  28. $ipFound = true;
  29. }
  30. // The ip address has been found, now rescan all the string
  31. // to get the mac address
  32. if ($ipFound) {
  33. // Rescan all the string, in case the mac address, in the string
  34. // returned by arp, comes before the ip address
  35. // (you know, Murphy's laws)
  36. reset($valueSplitted);
  37. foreach ($valueSplitted as $spLine) {
  38. if (preg_match("/[0-9a-f][0-9a-f][:-]".
  39. "[0-9a-f][0-9a-f][:-]".
  40. "[0-9a-f][0-9a-f][:-]".
  41. "[0-9a-f][0-9a-f][:-]".
  42. "[0-9a-f][0-9a-f][:-]".
  43. "[0-9a-f][0-9a-f]/i",$spLine)) {
  44. return $spLine;
  45. }
  46. }
  47. }
  48. $ipFound = false;
  49. }
  50. }
  51. return false;
  52. }
  53. echo returnmacaddress();
  54. ?>
I found this code by googling! But its not printing anything!! :(
Sep 10 '09 #1

✓ answered by Dormilich

why should the system ID / CPU ID be submitted? you can’t read what’s not provided.

if those computers have static IPs, you can use those.

29 37250
Dormilich
8,658 Expert Mod 8TB
then itís probably returning false, which does not have a print representation (check with var_dump()).
Sep 10 '09 #2
pradeepjain
563 512MB
@Dormilich
I did not get u!! :( !i have never used var_dump()!!
Sep 10 '09 #3
Dormilich
8,658 Expert Mod 8TB
@pradeepjain
shame on you, thatís probably the #1 debugging function in PHP. see ref.
Sep 10 '09 #4
pradeepjain
563 512MB
@Dormilich
okie!!i will learn now!!thanks for the comments !!
Sep 10 '09 #5
pradeepjain
563 512MB
I tried to print the $location value!!! it had nothin in it!!!
Sep 10 '09 #6
Dormilich
8,658 Expert Mod 8TB
@pradeepjain
where did you try to print it?
Sep 10 '09 #7
pradeepjain
563 512MB
after this line

Expand|Select|Wrap|Line Numbers
  1. $location = rtrim($location);
Sep 10 '09 #8
Dormilich
8,658 Expert Mod 8TB
may I see the code?

my output:
Expand|Select|Wrap|Line Numbers
  1. // formatted through xdebug
  2. string 'which arp' (length=9)
Sep 10 '09 #9
pradeepjain
563 512MB
@Dormilich
sorry for the mistake i am also getting 'which arp' ...
i dono y he he is using 'which arp ' here! i am not getting the logic in that code! so i am facing problem!
Sep 10 '09 #10
Dormilich
8,658 Expert Mod 8TB
hasnít there been a description?

besides the code usage looks odd.

this is what I found somewhere else and looks way more sensible.
Expand|Select|Wrap|Line Numbers
  1. $mac = `ping $ip && arp -a | grep $ip`;
Sep 10 '09 #11
pradeepjain
563 512MB
@Dormilich
okie thanks for help!will give it a try!
Sep 10 '09 #12
pradeepjain
563 512MB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ip = '192.168.2.213';
  3.  
  4.   $mac = `ping $ip && arp -a | grep $ip`;
  5. echo $mac;
  6. ?>
i wrote this code !!its printing nothing! i am getting an error in error log like

ping: icmp open socket: Permission denied when i run this code!
Sep 10 '09 #13
Dormilich
8,658 Expert Mod 8TB
to know what arp does go to a posix machine (linux, unix, bsd, mac), open a terminal (on linux you can also use ALT+F2), type
Expand|Select|Wrap|Line Numbers
  1. man arp
hit enter and read the description.
Sep 10 '09 #14
Dormilich
8,658 Expert Mod 8TB
@pradeepjain
thatís always the problem with shell commands, you need permission.
Sep 10 '09 #15
pradeepjain
563 512MB
so we cannot generally find the MAC id's of a machine connected to net as one of the problems will be permission!
Sep 10 '09 #16
Dormilich
8,658 Expert Mod 8TB
do you get the same result if you try
Expand|Select|Wrap|Line Numbers
  1. $mac = `arp -a | grep $ip`;
?
Sep 10 '09 #17
pradeepjain
563 512MB
@Dormilich
yeah!!!permission error!
Sep 10 '09 #18
Dormilich
8,658 Expert Mod 8TB
then you canít do anything about it (although the concept is right)
Sep 10 '09 #19
pradeepjain
563 512MB
is there any parameter by which we can recognize a system over internet ?
Jan 11 '10 #20
Dormilich
8,658 Expert Mod 8TB
recognize in what kind of way?
Jan 11 '10 #21
pradeepjain
563 512MB
like suppose if that system is accessing ma website its should be identified by unique thing specific to that comp! bcos we need to lock our website for a few ips' of outside internet!
Jan 11 '10 #22
Dormilich
8,658 Expert Mod 8TB
what is a "comp", company, computer, competitor?

do you mean allow certain IPs or exclude certain IPs?
Jan 11 '10 #23
pradeepjain
563 512MB
sorry for shortcuts..i mean to say a computer /pc
Jan 11 '10 #24
Dormilich
8,658 Expert Mod 8TB
is there anything specific about allowed/denied computers/clients?
Jan 11 '10 #25
pradeepjain
563 512MB
its like the website will be accessed at only 2 places say 2 hospitals so need to lock them to those places!
Jan 11 '10 #26
pradeepjain
563 512MB
IS there no solution for this problem . like i am using all linux machines . cant i uniquely identify the system accessing it .something like system ID / CPU ID.
Feb 2 '10 #27
Dormilich
8,658 Expert Mod 8TB
why should the system ID / CPU ID be submitted? you can’t read what’s not provided.

if those computers have static IPs, you can use those.
Feb 2 '10 #28
pradeepjain
563 512MB
nope !! but they use laptops for accessing the site. so they dont have a static IP's .
Feb 2 '10 #29
This functionality will work on a local network, but not the internet as the MAC is hidden by the clients router.

In short, the MAC is not present in the IP packet header.

You can retrieve the client IP address via <?php echo $_SERVER['REMOTE_ADDR']; ?> however this is not 100% accurate because of IP address spoofing.
Oct 15 '10 #30

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Marchello | last post by:
Hi All. I will try to explain my question on following example: Having class CInteger (wraper on 'int' values): class CInteger { public:...
1
by: eddiekwang | last post by:
Hello, Is it necessary to upgrade the Client Connectivity Tools on all client machines after the SQL Server database server is upgraded from...
4
by: Sean | last post by:
I've developed a VB6 application that uses a VB.Net dll. When distributed to client machines it works fine except for a few cases. The clients...
7
by: navin123 | last post by:
Im writing a code to retirve the mac address of the client. I hv the javascript dat retrives the mac address.. but it works only id the IE's security...
2
by: =?Utf-8?B?S2plbGw=?= | last post by:
Hi I'm new to C# and .Net so be nice :-) I'm going throught a steep learing curve right now and finding it really hard when after several...
5
by: =?Utf-8?B?ZGF2aWQ=?= | last post by:
I used Visual Studio .NEt 2003 to develop a web form in which there is a bmp format image. I used WebControls.Image in Design and set ImageUrl...
3
by: =?Utf-8?B?R2xlbm4gVGhpbW1lcw==?= | last post by:
Hello, I have a c# application hitting an asp.net web service. .net 2.0 I have been told by a customer of mine that it is necessary that I...
5
omerbutt
by: omerbutt | last post by:
can any body tell me the right code to get the client ip address,i have tried these two ways //$ip=@$REMOTE_ADDR; $ip=$_SERVER; but it...
1
by: kenny doel | last post by:
How to get IP list of a client machines in a network
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.