0

I'm doing a project for class and the professor has asked me to store the visitors IP address and MAC address to my database when they log in.

So far after hours of looking around I have been able to get the IP using PHP, but now I need to figure out how to get the MAC address.

From my research I can see that using iptables is the key. I have installed the packed onto my web server now just need some help on figuring out how to grab the data from iptables and output it into an echo command so I can see whats going on.

Well for starters, I would need to know how to capture the MAC address using iptables before figuring out how to use PHP in all of this.

Kenster
  • 18,710
  • 21
  • 68
  • 90
Eli
  • 4,150
  • 5
  • 41
  • 74
  • 10
    Do you understand that the source MAC address of a packet coming from anywhere but your own ethernet segment will be the MAC of the router? MAC addresses don't get sent across the Internet; they're LAN local. – Jim Garrison Oct 04 '10 at 21:07
  • @Jim Garrison - I understand that the MAC is on the client PC and can only be accessed by the system it is running on. But I was readidng up that I could use iptables with the MAC module to capture the MAC in the event that I wanted to restrict certain ranges onto my site. This is what I am trying to ask, how to get the MAC and how to add it to a database for later comparison. – Eli Oct 04 '10 at 21:25
  • The MAC is meaningless unless the remote system is on the local LAN segment. For any traffic originating outside your LAN segment the MAC will identify the router as the source. You cannot use MACs as a general filtering mechanism unless all the client systems are on your local LAN. – Jim Garrison Oct 05 '10 at 00:10
  • 2
    Duplicate of this question: http://stackoverflow.com/questions/1420381/php-mac-address – vls Oct 04 '10 at 21:18

1 Answers1

1

The MAC of the client is not on the wire outside of their local network segment(s) in such a case there's no way to determine it.

to check for locality do ip route get $ip_address and if there's no 'via' in the result they're on the same network. if they are you can grep for $ip_address in the arp table:

/usr/sbin/arp -n | fgrep $ip_address

Jasen
  • 10,276
  • 2
  • 23
  • 40