473,405 Members | 2,167 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 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 37443
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: ..... void SetValueFromPoiner(int *new_value)
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 Version 7.0 to 2000? Thank you in advance! Eddy
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 having problems seem to be missing RegAsm.exe from...
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 is set to low. If it is set to high it throws an...
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 hours of coding is running into security issue when...
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 property field to...
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 reduce the MTU size of all my outbound client web...
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 gives me 127.0.0.1 where as i want such figure...
1
by: kenny doel | last post by:
How to get IP list of a client machines in a network
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.