Determining MAC address

G

Glen Holcomb

[Note: parts of this message were removed to make it a legal post.]

What would be the best (clean, cross-platform) way of determining the MAC
address of a host when you have the hostname and IP address?
 
K

Kyle Schmitt

What would be the best (clean, cross-platform) way of determining the MAC
address of a host when you have the hostname and IP address?

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

There is an older project net-proto floating around. The same guy did
a sys/admin and sys/net library. One of those may give you the
information.

It would be probably be easier to check for OS type, and then call and
parse the output of ifconfig on real oses, and ipconfig on everything
else. Both ifconfig and ipconfig can give you the mac address, and it
won't take much slicing and dicing of the text to do it.

--Kyle
 
K

Kyle Schmitt

What would be the best (clean, cross-platform) way of determining the MAC
address of a host when you have the hostname and IP address?

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

And I need more coffee so I can read the posts more clearly, it's
early I mis-understood the first time ;)

I know nmap returns this sort of information when you scan a host, and
again, it's not too hard to slice up the nmap output (even if you
don't tell nmap to dump xml).

As far as all all ruby way, I'm sure there is one, but I'm unaware of it.
 
G

Glen Holcomb

[Note: parts of this message were removed to make it a legal post.]

And I need more coffee so I can read the posts more clearly, it's
early I mis-understood the first time ;)

I know nmap returns this sort of information when you scan a host, and
again, it's not too hard to slice up the nmap output (even if you
don't tell nmap to dump xml).

As far as all all ruby way, I'm sure there is one, but I'm unaware of it.
Thanks Kyle, nmap would be a descent Kludge for the time being. I'll keep
my eyes on this thread. I figured there was probably an all ruby way too
but didn't find much on google.
 
A

ara.t.howard

What would be the best (clean, cross-platform) way of determining
the MAC
address of a host when you have the hostname and IP address?

--
"Hey brother Christian with your high and mighty errand, Your
actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)


cfp:~ > sudo gem install macaddr
Successfully installed macaddr-0.0.2
1 gem installed


cfp:~ > ruby -r rubygems -e' require "macaddr"; p Mac.addr '
"00:1e:c2:42:42:42"


a @ http://codeforpeople.com/
 
S

Ståle Z.H

[Note:  parts of this message were removed to make it a legal post.]

What would be the best (clean, cross-platform) way of determining the MAC
address of a host when you have the hostname and IP address?

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

You could craft an ARP packet and put it on the wire. (I've written a
couple of classes that uses libnet and pcap to craft and capture ARP
packets if you're interested.) Of course, this requires the target to
be on the LAN. It might not be the easiest or cleanest way to do this,
but it should work and it should be cross-platform, heh.
 
G

Glen Holcomb

[Note: parts of this message were removed to make it a legal post.]

What would be the best (clean, cross-platform) way of determining the M= AC
address of a host when you have the hostname and IP address?

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

You could craft an ARP packet and put it on the wire. (I've written a
couple of classes that uses libnet and pcap to craft and capture ARP
packets if you're interested.) Of course, this requires the target to
be on the LAN. It might not be the easiest or cleanest way to do this,
but it should work and it should be cross-platform, heh.
Thanks for the ARP suggestion, I might be interested. Some of the machines
in question are on the same VLAN however others are not. Right now the
values have to be entered manually and for my area that isn't too big of a
pain as I only have around 70 machines. However to go institution wide tha=
t
would be a giant headache so any automation would be better than none.



--=20
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
 
S

Ståle Z.H

[Note:  parts of this message were removed to make it a legal post.]
What would be the best (clean, cross-platform) way of determining theMAC
address of a host when you have the hostname and IP address?
You could craft an ARP packet and put it on the wire. (I've written a
couple of classes that uses libnet and pcap to craft and capture ARP
packets if you're interested.) Of course, this requires the target to
be on the LAN. It might not be the easiest or cleanest way to do this,
but it should work and it should be cross-platform, heh.

Thanks for the ARP suggestion, I might be interested.  Some of the machines
in question are on the same VLAN however others are not.  Right now the
values have to be entered manually and for my area that isn't too big of a
pain as I only have around 70 machines.  However to go institution widethat
would be a giant headache so any automation would be better than none.

--
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)

Alright, you could of course just use a laptop and connect it to each
network in turn if the machines aren't spread across too many
networks. Just send me an email or whatever if you're interested in
the ARP injection/capture code. :)
 
P

Peña, Botp

From: Glen Holcomb [mailto:[email protected]]=20
# Thanks for the ARP suggestion, I might be interested. Some=20
# of the machines in question are on the same VLAN however others
# are not. Right now the values have to be entered manually and=20
# for my area that isn't too big of a pain as I only have around 70
# machines. However to go institution wide that would be a giant
# headache so any automation would be better than none.

arps do not cross beyond networks, you'll have to gather the data fr the =
junctions. if you have access to the routers/switches, you can see the =
arp table. If you use telnet or ssh, you can create a script to automate =
and collate everything. A nice project would be to create a map of your =
network showing wc nodes are connected to wc switch/router...

kind regards -botp
=20
 
G

Glen Holcomb

From: Glen Holcomb [mailto:[email protected]]
# Thanks for the ARP suggestion, I might be interested. Some
# of the machines in question are on the same VLAN however others
# are not. Right now the values have to be entered manually and
# for my area that isn't too big of a pain as I only have around 70
# machines. However to go institution wide that would be a giant
# headache so any automation would be better than none.

arps do not cross beyond networks, you'll have to gather the data fr the
junctions. if you have access to the routers/switches, you can see the ar= p
table. If you use telnet or ssh, you can create a script to automate and
collate everything. A nice project would be to create a map of your netwo= rk
showing wc nodes are connected to wc switch/router...

kind regards -botp
Thanks guys, I don't have direct access to the routers/switches
unfortunately.

This whole thing started as a tool to shutdown certain machines at certain
times in the evening and then wake them (WOL) at a scheduled time in the
morning to be ready for classes. I only manage three labs so it wasn't a
big deal to input the MAC addresses by hand. However the larger IT
department here at the school has taken notice and is interested in using i=
t
to manage machines institution wide.

Since they have over a thousand machines they manage the current idea is to
populate both the computer db entries and the group/lab/area db entries fro=
m
LDAP/AD. Hence my quest for an easily automated way to get MAC addresses,
machine names are easy (LDAP/AD) and IP is also easy, at least assuming DNS
is correct it is.

I've also run into an issue where the machines on the subdomain I work in
give themselves a different IP than that which the DHCP server thinks they
should have in DNS. Needless to say this has been a ton of fun. For some
reason the Primary Domain Controller in this domain has different DNS
records from all the other DNS servers and most annoyingly they are
different from the DHCP servers DNS entries for these machines (The main
DHCP server does DNS too). This is a very Windows problem and is driving m=
e
crazy since I'm not the admin here.

If anyone knows a quick solution to this issue I would consider paying
weekly tribute ;) If I can't get to the right machine I can't shut it down
remotely.

That would be the ultimate irony, a tool I wrote to manage my equipment onl=
y
working for others in the company (the main IT department).

--=20
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can't hear a word you're saying."

-Greg Graffin (Bad Religion)
 
B

brabuhr

This whole thing started as a tool to shutdown certain machines at certain
times in the evening and then wake them (WOL) at a scheduled time in the
morning to be ready for classes. I only manage three labs so it wasn't a
big deal to input the MAC addresses by hand. However the larger IT
department here at the school has taken notice and is interested in using it
to manage machines institution wide.

Since they have over a thousand machines they manage the current idea is to
populate both the computer db entries and the group/lab/area db entries from
LDAP/AD. Hence my quest for an easily automated way to get MAC addresses,
machine names are easy (LDAP/AD) and IP is also easy, at least assuming DNS
is correct it is.

If you are talking about mainly Windows boxes and they still have the
NetBIOS bits enabled, try nbtstat:

C:\>nbtstat -A 172.16.121.11

Local Area Connection:
Node IpAddress: [172.16.121.54] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
...

MAC Address = XX-XX-XX-XX-XX-XX

C:\>nbtstat -A 172.16.23.204

Local Area Connection:
Node IpAddress: [172.16.121.54] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
 
G

Glen Holcomb

[Note: parts of this message were removed to make it a legal post.]

This whole thing started as a tool to shutdown certain machines at certain
times in the evening and then wake them (WOL) at a scheduled time in the
morning to be ready for classes. I only manage three labs so it wasn't a
big deal to input the MAC addresses by hand. However the larger IT
department here at the school has taken notice and is interested in using it
to manage machines institution wide.

Since they have over a thousand machines they manage the current idea is to
populate both the computer db entries and the group/lab/area db entries from
LDAP/AD. Hence my quest for an easily automated way to get MAC addresses,
machine names are easy (LDAP/AD) and IP is also easy, at least assuming DNS
is correct it is.

If you are talking about mainly Windows boxes and they still have the
NetBIOS bits enabled, try nbtstat:

C:\>nbtstat -A 172.16.121.11

Local Area Connection:
Node IpAddress: [172.16.121.54] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
---------------------------------------------
...

MAC Address = XX-XX-XX-XX-XX-XX

C:\>nbtstat -A 172.16.23.204

Local Area Connection:
Node IpAddress: [172.16.121.54] Scope Id: []

NetBIOS Remote Machine Name Table

Name Type Status
Thanks brabuhr,

Most of the target machines are definitely Windows boxes and the app will
probably reside on a Windows box so this would work in that case.

Much appreciated.

-Glen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top