[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

get mac address

tristan

6/12/2015 5:49:00 AM

Hello
Do you know if a lib exist for getting the mac adress of a device in my
network, knowing his ip adress; like "network-info" for haskell?
Thanks
11 Answers

Pascal J. Bourguignon

6/12/2015 9:30:00 AM

0

grobibi <tristanhennequin@free.fr> writes:

> Do you know if a lib exist for getting the mac adress of a device in
> my network, knowing his ip adress; like "network-info" for haskell?

This is the job of ARP.

Unfortunately the Address Resolution Protocol is buried deep into IP,
that is, inside the kernels, and there's no "standard" API to perform
your own requests to it.

Therefore the answer will depend on your target system.

On Linux, you can send a ping packet to the IP address (or a ping
broadcast), and then look at the /proc/net/arp pseudo file to find the
MAC corresponding to the IP address. The advantage of using
/proc/net/arp is that you can do that with conforming CL code, without
using any extension (but read byte-by-byte, not using READ-SEQUENCE,
since some implementations have problems determining the file length for
those pseudo files).


Alternatively, you may use the arp(8) command, but then you have to
parse its output which won't necessarily be the same format on all
systems.

--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

tristan

6/12/2015 7:18:00 PM

0

Le 12/06/2015 11:30, Pascal J. Bourguignon a écrit :
> grobibi <tristanhennequin@free.fr> writes:
>
>> Do you know if a lib exist for getting the mac adress of a device in
>> my network, knowing his ip adress; like "network-info" for haskell?
>
> This is the job of ARP.
>
> Unfortunately the Address Resolution Protocol is buried deep into IP,
> that is, inside the kernels, and there's no "standard" API to perform
> your own requests to it.
>
> Therefore the answer will depend on your target system.
>
> On Linux, you can send a ping packet to the IP address (or a ping
> broadcast), and then look at the /proc/net/arp pseudo file to find the
> MAC corresponding to the IP address. The advantage of using
> /proc/net/arp is that you can do that with conforming CL code, without
> using any extension (but read byte-by-byte, not using READ-SEQUENCE,
> since some implementations have problems determining the file length for
> those pseudo files).
>
>
> Alternatively, you may use the arp(8) command, but then you have to
> parse its output which won't necessarily be the same format on all
> systems.
>
Thanks a lot. Permite me, Mr Bourguignon to answser in french, i'm very
tired and I don't know if I will speek in good english today:

Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
l'adresse ip d'un switch connaissant uniquement son adresse mac. Facile,
sous windows, un petit scan sur une plage d'adresses ip avec un petit
script d'une ligne, puis extraction de l'adresse via arp... Encore plus
facile avec un scanner quelconque récupéré sur le web.
Mais programmer tout ça serait encore plus agréable! En lisp qui plus
est. En somme, pas de solution unique, pas de panacée, comme d'habitude.
Bonne continuation.
TH


smh

6/12/2015 11:08:00 PM

0

On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:

> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
> l'adresse ip d'un switch connaissant uniquement son adresse mac. Facile,
> sous windows, un petit scan sur une plage d'adresses ip avec un petit
> script d'une ligne, puis extraction de l'adresse via arp... Encore plus
> facile avec un scanner quelconque récupéré sur le web.
> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
> est. En somme, pas de solution unique, pas de panacée, comme d'habitude.

When thinking about obtaining the MAC address of a computer, remember that there is no guarantee that a computer will have exactly one MAC address. A single MAC address might be the case for most of the machines on which one runs Common Lisp, but there is no guarantee. Even for a plain single-inet interface machine like a laptop, installation of virtual machines might confuse things.

Most operating systems have a shell-runnable program like Linux ipconfig which prints a report of the network devices and configuration. A regexp match against that output would be one way to get what you want.

Barry Margolin

6/12/2015 11:46:00 PM

0

In article <e4fdf362-14f0-41af-9637-d63b9cf2f0e6@googlegroups.com>,
smh <shaflich@gmail.com> wrote:

> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
>
> > Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
> > l'adresse ip d'un switch connaissant uniquement son adresse mac. Facile,
> > sous windows, un petit scan sur une plage d'adresses ip avec un petit
> > script d'une ligne, puis extraction de l'adresse via arp... Encore plus
> > facile avec un scanner quelconque récupéré sur le web.
> > Mais programmer tout ça serait encore plus agréable! En lisp qui plus
> > est. En somme, pas de solution unique, pas de panacée, comme d'habitude.
>
> When thinking about obtaining the MAC address of a computer, remember that
> there is no guarantee that a computer will have exactly one MAC address. A
> single MAC address might be the case for most of the machines on which one
> runs Common Lisp, but there is no guarantee. Even for a plain single-inet
> interface machine like a laptop, installation of virtual machines might
> confuse things.

While a computer may have multiple NICs, each with a different MAC
address, they'll usually have different IPs assigned to each. In the OP
he asked for a way to get the MAC address corresponding to a particular
IP. The ARP cache will only have one mapping for each IP.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

tristan

6/13/2015 8:50:00 AM

0

Le 13/06/2015 01:45, Barry Margolin a écrit :
> In article <e4fdf362-14f0-41af-9637-d63b9cf2f0e6@googlegroups.com>,
> smh <shaflich@gmail.com> wrote:
>
>> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
>>
>>> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
>>> l'adresse ip d'un switch connaissant uniquement son adresse mac. Facile,
>>> sous windows, un petit scan sur une plage d'adresses ip avec un petit
>>> script d'une ligne, puis extraction de l'adresse via arp... Encore plus
>>> facile avec un scanner quelconque récupéré sur le web.
>>> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
>>> est. En somme, pas de solution unique, pas de panacée, comme d'habitude.
>>
>> When thinking about obtaining the MAC address of a computer, remember that
>> there is no guarantee that a computer will have exactly one MAC address. A
>> single MAC address might be the case for most of the machines on which one
>> runs Common Lisp, but there is no guarantee. Even for a plain single-inet
>> interface machine like a laptop, installation of virtual machines might
>> confuse things.
>
> While a computer may have multiple NICs, each with a different MAC
> address, they'll usually have different IPs assigned to each. In the OP
> he asked for a way to get the MAC address corresponding to a particular
> IP. The ARP cache will only have one mapping for each IP.
>
I understand what you are saying, but in this case, the job was to find
a switch in the network, not a computer...

Robert Swindells

6/13/2015 11:33:00 AM

0

On Sat, 13 Jun 2015 10:49:55 +0200, grobibi wrote:

> Le 13/06/2015 01:45, Barry Margolin a écrit :
>> In article <e4fdf362-14f0-41af-9637-d63b9cf2f0e6@googlegroups.com>,
>> smh <shaflich@gmail.com> wrote:
>>
>>> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
>>>
>>>> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
>>>> l'adresse ip d'un switch connaissant uniquement son adresse mac.
>>>> Facile, sous windows, un petit scan sur une plage d'adresses ip avec
>>>> un petit script d'une ligne, puis extraction de l'adresse via arp...
>>>> Encore plus facile avec un scanner quelconque récupéré sur le web.
>>>> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
>>>> est. En somme, pas de solution unique, pas de panacée, comme
>>>> d'habitude.

[snip]

> I understand what you are saying, but in this case, the job was to find
> a switch in the network, not a computer...

But a switch doesn't have a MAC (or IP) address.

Is "switch" a false friend and you are actually trying to find a router ?

If your Lisp is running on a UNIX and has a binding to socket(2) then you
could query the routing table directly, this is what the arp program does.

Pascal J. Bourguignon

6/13/2015 1:35:00 PM

0

Robert Swindells <rjs@fdy2.co.uk> writes:

> On Sat, 13 Jun 2015 10:49:55 +0200, grobibi wrote:
>
>> Le 13/06/2015 01:45, Barry Margolin a écrit :
>>> In article <e4fdf362-14f0-41af-9637-d63b9cf2f0e6@googlegroups.com>,
>>> smh <shaflich@gmail.com> wrote:
>>>
>>>> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
>>>>
>>>>> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
>>>>> l'adresse ip d'un switch connaissant uniquement son adresse mac.
>>>>> Facile, sous windows, un petit scan sur une plage d'adresses ip avec
>>>>> un petit script d'une ligne, puis extraction de l'adresse via arp...
>>>>> Encore plus facile avec un scanner quelconque récupéré sur le web.
>>>>> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
>>>>> est. En somme, pas de solution unique, pas de panacée, comme
>>>>> d'habitude.
>
> [snip]
>
>> I understand what you are saying, but in this case, the job was to find
>> a switch in the network, not a computer...
>
> But a switch doesn't have a MAC (or IP) address.

Smart-switches have a MAC and IP address so that you can administrate
them remotely, configuring the ports and connections.



--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

Barry Margolin

6/13/2015 2:18:00 PM

0

In article <87si9vwx2g.fsf@kuiper.lan.informatimago.com>,
"Pascal J. Bourguignon" <pjb@informatimago.com> wrote:

> Robert Swindells <rjs@fdy2.co.uk> writes:
>
> > On Sat, 13 Jun 2015 10:49:55 +0200, grobibi wrote:
> >
> >> Le 13/06/2015 01:45, Barry Margolin a écrit :
> >>> In article <e4fdf362-14f0-41af-9637-d63b9cf2f0e6@googlegroups.com>,
> >>> smh <shaflich@gmail.com> wrote:
> >>>
> >>>> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
> >>>>
> >>>>> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
> >>>>> l'adresse ip d'un switch connaissant uniquement son adresse mac.
> >>>>> Facile, sous windows, un petit scan sur une plage d'adresses ip avec
> >>>>> un petit script d'une ligne, puis extraction de l'adresse via arp...
> >>>>> Encore plus facile avec un scanner quelconque récupéré sur le web.
> >>>>> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
> >>>>> est. En somme, pas de solution unique, pas de panacée, comme
> >>>>> d'habitude.
> >
> > [snip]
> >
> >> I understand what you are saying, but in this case, the job was to find
> >> a switch in the network, not a computer...

I didn't know that. Now I see that it's in the the French post that I
didn't bother to translate (has l'Academie Francaise really approved
"switch"?). I've translated it now.

For his purposes, the distinction between a switch and other hosts is
irrelevant. It's just a host on the LAN that happens to perform the
switching role.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Kaz Kylheku

6/13/2015 2:42:00 PM

0

On 2015-06-12, smh <shaflich@gmail.com> wrote:
> On Friday, June 12, 2015 at 12:18:05 PM UTC-7, grobibi wrote:
>
>> Un jeune stagiaire est arrivé au boulot, je lui ai demandé de trouver
>> l'adresse ip d'un switch connaissant uniquement son adresse mac. Facile,
>> sous windows, un petit scan sur une plage d'adresses ip avec un petit
>> script d'une ligne, puis extraction de l'adresse via arp... Encore plus
>> facile avec un scanner quelconque récupéré sur le web.
>> Mais programmer tout ça serait encore plus agréable! En lisp qui plus
>> est. En somme, pas de solution unique, pas de panacée, comme d'habitude.
>
> When thinking about obtaining the MAC address of a computer, remember that
> there is no guarantee that a computer will have exactly one MAC address.

He's getting the MAC for a given IP on a network. A given IP on your network
will not have two MACs. If the same hardware exhibits multiple macs, they will
have different IP's (e.g. virtual OS images running on the same host machine,
sharing the same adapter).

> single MAC address might be the case for most of the machines on which one
> runs Common Lisp, but there is no guarantee. Even for a plain single-inet
> interface machine like a laptop, installation of virtual machines might
> confuse things.

Not really. Virtual machines are effectively separate machines. You have
separate ARP entries for them in your ARP cache, with different IP's and MACs.

(Virtual machines that use NAT are effectively not on your network segment;
they are out of scope of the problem.)

Kaz Kylheku

6/13/2015 2:43:00 PM

0

On 2015-06-13, grobibi <tristanhennequin@free.fr> wrote:
> I understand what you are saying, but in this case, the job was to find
> a switch in the network, not a computer...

Surely you mean, "router".

A switch is transparent; it copies packets from one port to another,
and is never itself addressed by any of them.