rhymejerky has asked for the wisdom of the Perl Monks concerning the following question:
|
|---|
| Replies are listed 'Best First'. | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Re: getting mac address
by SciDude (Friar) on Oct 09, 2004 at 01:07 UTC | |||||||||||||
This is not exactly a perl question... but here is one answer. Simple MAC queries depend upon the operating system used:
In addition, you can also find the MAC of all computers on your network. If using linux, the arp utility (/sbin/arp) will display cached arp requests on your machine:
You may have to ping the machine first to ensure the information is contained in the cache. Manufacturer InformationOn a side note, the first 24 bits of the MAC identifies the device manufacturer via the Organizationally Unique Identifiers (OUI). A simple perl script can probe the IEEE database of OUI to determine the related hardware per MAC address. CPANYou may also want to look at SNMP::BridgeQuery | [reply] [d/l] | ||||||||||||
|
Re: getting mac address
by tachyon (Chancellor) on Oct 09, 2004 at 05:04 UTC | |||||||||||||
Short story: outside of your immediate LAN you can't get the MAC of the originator. Longer version :-) 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. Using the arp table useful but only up to a certain point. The mac address is put into the IP packet at the 2nd level of the OSI model 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 to most recent handler" address, rather than a "Return to sender" 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, whereas the IP address won't. Example: Machine A sends a packet to Machine B, and it passes through Firewall C and Router D. The packet does this: cheers tachyon | [reply] | ||||||||||||
|
Re: getting mac address
by Fletch (Bishop) on Oct 09, 2004 at 01:09 UTC | |||||||||||||
Basically you'll have to read your system's ARP table and match that up with the source IP. The simplest thing is to parse the output of the arp command, or possibly netstat -nr depending on your OS (for UNIX-y values of OS, of course). | [reply] | ||||||||||||
|
Re: getting mac address
by NetWallah (Canon) on Oct 09, 2004 at 05:23 UTC | |||||||||||||
Step 1 Determine the MAC addresses of the hosts you want to be assigned to VLANs dynamically. using the command show cam Earth first! (We'll rob the other planets later) | [reply] | ||||||||||||
|
Re: getting mac address
by tmoertel (Chaplain) on Oct 09, 2004 at 14:14 UTC | |||||||||||||
The Internet Software Consortium DHCP Server keeps a persistent database of leases that it has assigned. This database is a free-form ASCII file containing a series of lease declarations. Every time a lease is acquired, renewed or released, its new value is recorded at the end of the lease file. So if more than one declaration appears for a given lease, the last one in the file is the current one.Thus you could use File::Tail or a similar means to monitor the leases file and act upon new leases as they appear. The typical lease entry looks like this: Note the "hardware ethernet" field, which contains the MAC address of the host. You can easily grab this with a simple regex like /hardware\s+ethernet\s+([0-9a-f:]+);/i. The nice thing about this approach is that you get a two-for-one bonus: When a host plugs into your network, you will receive instant notification of the fact via an addition to the leases database, and the notification will hand you the MAC address on a silver platter. Hope this helps! Cheers, Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder | [reply] [d/l] [select] | ||||||||||||
by rhymejerky (Beadle) on Oct 11, 2004 at 16:55 UTC | |||||||||||||
| [reply] | ||||||||||||
by tmoertel (Chaplain) on Oct 11, 2004 at 18:30 UTC | |||||||||||||
What I really want to do is trigger something and grab the user's MAC and see if the laptop is authorized. I know grab MAC address using ipconfig, but I want to automate this part.The "trigger" is the appearance of a new entry in the DHCP leases database. The entry will contain the MAC address already, so there is no need to look it up using ipconfig. For example, here is some (untested) code that monitors the lease database and triggers a call to check_authorization when a new lease record appears: Hope this helps. Cheers! Tom Moertel : Blog / Talks / CPAN / LectroTest / PXSL / Coffee / Movie Rating Decoder | [reply] [d/l] [select] | ||||||||||||
|
Re: getting mac address
by Magrini (Initiate) on Oct 23, 2004 at 15:06 UTC | |||||||||||||
| [reply] | ||||||||||||