|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
How can I find out the user MAC ADDRESS?
I've read in deffirent articles about anonymousity that it's possible but I didn't find it in the server variables
any one knows how to do it?? in php if possible |
|
#2
|
|||
|
|||
|
I don't think you can find the MAC address directly from PHP - it's not something that that is included in the http headers that a browser sends, so will not be present in server variables.
There does seem to be software available to find a MAC address given a IP address (google for "find mac address ip") but it only seems to work over a local network. Why do you want the MAC address anyway? Hadley |
|
#3
|
|||
|
|||
|
I want to deny any one from accessing the site except one person on sprcified machine
and becuase he doesn't have dedicated IP address so I don't have other wayt o make sure that he is the right person and I read an article before about Anonymity that talks about the thing a web site can knows about you and they said that he can know your MAC address |
|
#4
|
|||
|
|||
|
Perhaps an easier way would be to use a username and password?
Hadley |
|
#5
|
|||
|
|||
|
if you really want his MAC address one solution would be to shell out some command line tools and parse their output, on *nix I think doing this would get the mac address:
PHP Code:
The output may have to be parsed, and I'm unsure if you can include varibles inside backticks... As previously stated this will only work on a local network, so via the internet is a no no... Also I should note that its possible to spoof MAC Address, so don't reply 100% on them bramp |
|
#6
|
|||
|
|||
|
You'll have to find some other solution, using a MAC address will be impossible unless you're on a LAN. Even on a LAN, you couldn't do this from php without jumping through hoops.
|
|
#7
|
|||
|
|||
|
thanks a lot ppl
it's all clear now |
|
#8
|
|||
|
|||
|
Please, if you already know how to get the mac address from a user would you send to me how to do it???? I realy realy ned it!! thanks. My e-mail is: URL
![]() |
|
#9
|
||||
|
||||
|
Because of the way that the internet was designed and the way that the IP protocol works, you wouldn't be able to find a mac address of someone unless you were local to them. The post earlier about using ping and arp is correct. The mac address is put into the IP packet at the 2nd level of the OSI model, its a physical address... once you go out through a router the mac address of the reported packet is changed, and is changed each and every time.. think of the mac as a "Return" address. You send out a packet and it goes across the country, and goes through 5 routers, the mac address on the packet will change each and every time it goes through a router, where the IP address won't. It's a type of routing code that the routers use to identify where the packet came from and where to send a response to.
example Machine A sends a packet to Machine B, and it passes through Firewall C and D. The packet does this: Machine A sends the packet to firewall C, firwall C repackages the packet with its mac address and looks for the quickest route to machine B, it determines that firewall D is the closest to it, so it repackages the packet with its own mac address (since that is where D will send a response to if it cant get to machine B) and sends it on to D.. D does the exact same thing and sends the packet to B. Once Machine B receives the packet the entire process starts over again, the last mac address that is reported is for firewall D, but the IP points to Machine A, thats how it knows where to go. HTH ![]() Quote:
|
|
#10
|
|||
|
|||
|
php function to get mac address
function returnMacAddress() {
// This code is under the GNU Public Licence // Written by michael_stankiewicz {don't spam} at yahoo {no spam} dot com // Tested only on linux, please report bugs // WARNING: the commands 'which' and 'arp' should be executable // by the apache user; on most linux boxes the default configuration // should work fine // Get the arp executable path $location = `which arp`; // Execute the arp command and store the output in $arpTable $arpTable = `$location`; // Split the output so every line is an entry of the $arpSplitted array $arpSplitted = split("\n",$arpTable); // Get the remote ip address (the ip address of the client, the browser) $remoteIp = $GLOBALS['REMOTE_ADDR']; // Cicle the array to find the match with the remote ip address foreach ($arpSplitted as $value) { // Split every arp line, this is done in case the format of the arp // command output is a bit different than expected $valueSplitted = split(" ",$value); foreach ($valueSplitted as $spLine) { if (preg_match("/$remoteIp/",$spLine)) { $ipFound = true; } // The ip address has been found, now rescan all the string // to get the mac address if ($ipFound) { // Rescan all the string, in case the mac address, in the string // returned by arp, comes before the ip address // (you know, Murphy's laws) reset($valueSplitted); foreach ($valueSplitted as $spLine) { if (preg_match("/[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f]/i",$spLine)) { return $spLine; } } } $ipFound = false; } } return false; } |
|
#11
|
|||
|
|||
|
returnMacAddress now works better
Hy all
as mentioned before, be sure to understand the basics of the arp table since you can be sure that the obtained mac address is the right one only if the client is connected DIRECTLY to the php server, if there are routers or gateways that NAT the traffic, the returned mac address will be that of the gateway, not the client beside it thanks to marcus [riptide@digitaltorque.com] for some hacks on this code function returnMacAddress() { // This code is under the GNU Public Licence // Written by michael_stankiewicz {don't spam} at yahoo {no spam} dot com // Tested only on linux, please report bugs // WARNING: the commands 'which' and 'arp' should be executable // by the apache user; on most linux boxes the default configuration // should work fine // Get the arp executable path $location = `which arp`; $location = rtrim($location); // Execute the arp command and store the output in $arpTable $arpTable = `$location -n`; // Split the output so every line is an entry of the $arpSplitted array $arpSplitted = split("\n",$arpTable); // Get the remote ip address (the ip address of the client, the browser) $remoteIp = $GLOBALS['REMOTE_ADDR']; $remoteIp = str_replace(".", "\\.", $remoteIp); // Cicle the array to find the match with the remote ip address foreach ($arpSplitted as $value) { // Split every arp line, this is done in case the format of the arp // command output is a bit different than expected $valueSplitted = split(" ",$value); foreach ($valueSplitted as $spLine) { if ( preg_match("/$remoteIp/",$spLine) ) { $ipFound = true; } // The ip address has been found, now rescan all the string // to get the mac address if ($ipFound) { // Rescan all the string, in case the mac address, in the string // returned by arp, comes before the ip address (you know, Murphy's laws) reset($valueSplitted); foreach ($valueSplitted as $spLine) { if ( preg_match("/[0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f][:-]". "[0-9a-f][0-9a-f][:-][0-9a-f][0-9a-f]/i",$spLine)) { return $spLine; } } } $ipFound = false; } } return false; } |
|
#12
|
|||
|
|||
|
This does not seem to work outside my local network
I got this code to work but cannot get an ip outside of my local lan. Any thoughts.
Quote:
|
|
#13
|
|||
|
|||
|
This might help as a technique:
http://edge.mcs.drexel.edu/GICL/people/sevy/snmp/snmp_package_introduction.html |
|
#14
|
|||
|
|||
|
Windows PHP Mac address resolution
A Windows adoption of code Written by michael_stankiewicz (See above)
//any comments welcome 1samsj58 at solent dot ac dot uk tested on windows XP SP1 and windows 98 SE both contained 4 ARP table entrees. I wanted to write it my self to completely under stand how it worked, I believe that through only retrieving one line of the ARP table this has reduced the complexity of the script and reduced the work of sorting a little, after viewing the output of converted script that removed extra spaces it became apparent the MAC address was always followed the IP address by one element. As you can see this is how i retrieved the MAC address from within the array using a loop to match the IP address and then obtain the next element. Although I do believe that using the regular expression would be better general practice it worked fine for me. //First get the IP address then use the //DOS command + only get row with client IP address //This takes only one line of the ARP table instead //of what could be a very large table of data to //hopefull give a small speed/performance advantage $remoteIp = rtrim($_SERVER['REMOTE_ADDR']); $location = rtrim(`arp -a $remoteIp`); print_r($remoteIp.$location);//display //reduce no of white spaces then //Split up into array element by white space $location = preg_replace('/\s+/', 's', $location); $location = split('\s',$location);// $num=count($location);//get num of array elements $loop=0;//start at array element 0 while ($loop<$num) { //mac address is always one after the //IP after inserting the firstline //(preg_replace) line above. if ($location[$loop]==$remoteIp) { $loop=$loop+1; echo "<h1>Client MAC Address:- ".$location[$loop]."</h1>"; $_SESSION['MAC'] = $loop; return; } else {$loop=$loop+1;} } } ?> Last edited by SamsJ : April 13th, 2005 at 10:38 AM. Reason: Change its formating |
|
#15
|
|||
|
|||
|
When I run that script as-is in Mac OS X (FreeBSD variant) I get this error on my log:
Code:
usage: arp [-n] hostname
arp [-n] -a
arp -d hostname [pub]
arp -d -a
arp -s hostname ether_addr [temp] [pub]
arp -S hostname ether_addr [temp] [pub]
arp -f filename
If I add the -a flag to arp it no longer errors, but I still get a blank page. I made sure all of the comment lines weren't accidentally wrapped, as that was my first problem. This doesn't seem to want to work. I made sure that after the function I called it. Any thoughts? |
|
#16
|
|||
|
|||
|
Code:
// WARNING: the commands 'which' and 'arp' should be executable I have complete access to apache2-configuration, but how can I do this? Thanks, Tobi |