get ip from mac

B

BigZero

hello ppl,
is there any way or posable to get a ip-Address from mac address, i
mean that i have the mac address of a machine and i want to known the
ip address of that mac id or machine.....




Thanks
VM
 
T

Thomas Schodt

BigZero said:
hello ppl,
is there any way or posable to get a ip-Address from mac address, i
mean that i have the mac address of a machine and i want to known the
ip address of that mac id or machine.....

arp -a
 
N

Nigel Wade

BigZero said:
hello ppl,
is there any way or posable to get a ip-Address from mac address, i
mean that i have the mac address of a machine and i want to known the
ip address of that mac id or machine.....

Directly from Java? None that I know of.

What you want is ARP (address resolution protocol) which maps between IP and
Ethernet MAC. A typical scenario is first to ping the machine (it doesn't
matter whether the ping succeeds), or attempt to open a socket, to ensure that
the ARP cache has an entry for the machine in question. Then you query the ARP
cache by some means.
 
B

BigZero

Directly from Java? None that I know of.

What you want is ARP (address resolution protocol) which maps between IP and
Ethernet MAC. A typical scenario is first to ping the machine (it doesn't
matter whether the ping succeeds), or attempt to open a socket, to ensure that
the ARP cache has an entry for the machine in question. Then you query the ARP
cache by some means.

well i m getting mac address from SNMP, i known that i can get ip
address if i query the ip OID.
but the ip address changes(DHCP) so we want to keep the history of a
machine so i m using mac address that never changes, so here all want
to known is that is it possible to ip from mac address or can i query
the snmp with mac address.....


Thanks
VM
 
N

Nigel Wade

BigZero said:
well i m getting mac address from SNMP, i known that i can get ip
address if i query the ip OID.
but the ip address changes(DHCP) so we want to keep the history of a
machine so i m using mac address that never changes, so here all want
to known is that is it possible to ip from mac address or can i query
the snmp with mac address.....

Sorry, can't help with SNMP. I've never used it.

We are prohibited by local edict from using SNMP. SNMP is restricted to the
central IT dept. who use it to manage their own equipment.
 
B

BigZero

Sorry, can't help with SNMP. I've never used it.

We are prohibited by local edict from using SNMP. SNMP is restricted to the
central IT dept. who use it to manage their own equipment.

hey no problem thanks, i hope somebody may worked on that thing, all i
get stuck in get all ip from a single packet request that is
"broadcasting",
i m enable do this in snmp or non-snmp(simple java) program,
 
M

Mark Rafn

BigZero said:
is there any way or posable to get a ip-Address from mac address, i
mean that i have the mac address of a machine and i want to known the
ip address of that mac id or machine.....

This requires more context. A given mac address can have multiple IP
addresses, and the only mappings between them are local to the networking
stack on that host, and in the arp tables of hosts on the same ethernet
segment. Outside the local network segment, there is no knowledge of mac
addresses: they are not part of IP, they're part of ethernet.

As others have said, you might look into smtp for connecting to that host and
querying information about it. Or if you're on the same segment, look at your
own arp tables (see the arp command if you're on a unix-like machine).

Otherwise, look for a different way to solve whatever your real problem is.
 
T

Tom Anderson

Directly from Java? None that I know of.

What you want is ARP (address resolution protocol) which maps between IP
and Ethernet MAC. A typical scenario is first to ping the machine (it
doesn't matter whether the ping succeeds), or attempt to open a socket,
to ensure that the ARP cache has an entry for the machine in question.

Ah, but if you know the MAC address but not the IP, you can't do that.

I think you'd need to do something like craft an IP packet which had the
broadcast address as a destination, then send it to the right MAC address
using a raw socket. Actually, not even a raw socket, a SOCK_PACKET or
something. Yikes. Anyway, it should be something that elicits a response
that will put the mapping into the ARP cache. A normal ARP request might
do it, unless your host ignores apparently-unsolicited ARP responses. I'm
trying to work out if there's a way to provoke the target into emitting an
ARP announcement, but i can't think of anything.

You might just have to cross your fingers and hope the target is already
in your ARP cache!
Then you query the ARP cache by some means.

Yes. I can't find anything better than arp -a, as Thomas Schodt suggested.
There doesn't seem to be a portable API to arp; linux has some ioctls, and
/proc/net/arp, but that's it.

The OP should probably try a networking group with this question.

tom
 
A

Arne Vajhøj

BigZero said:
hey no problem thanks, i hope somebody may worked on that thing, all i
get stuck in get all ip from a single packet request that is
"broadcasting",
i m enable do this in snmp or non-snmp(simple java) program,

If you want to give SNMP a try, then:

http://www.snmp4j.org/

may save you some of the low level work.

Arne
 
T

Tom Anderson

Quite, one of those "Duh!" moments...

I know what you mean! The weird thing is, i can't for the life of me
figure out what a MAC-based ping would look like. Could you do it with the
broadcast IP address and the target's MAC address? Would your host ignore
the response? Would it end up in the ARP tables?

tom
 
N

Nigel Wade

Tom said:
I know what you mean! The weird thing is, i can't for the life of me
figure out what a MAC-based ping would look like.

Is there any such thing as a MAC based ping? Ping is an ICMP protocol and surely
requires an IP address? Hence the "Duh!", as that part of my response didn't
apply to the question the OP asked, get the IP from the MAC. As my physics
teacher took pains to point out - read the question carefully and answer the
question that is asked, you get no marks for answering a different question no
matter how correct your answer might be.
Could you do it with the
broadcast IP address and the target's MAC address?

I don't think you could use the target's MAC address, a broadcast should got to
each machine. I have never looked at a broadcast packet to see what MAC address
is used in the Ethernet frame (not even sure how to), maybe the MAC for the
default route?

Would your host ignore
the response? Would it end up in the ARP tables?

I've just tried a broadcast ping. I didn't receive any replies, but the ARP
table was populated by every pingable host.

--
Nigel Wade
 
T

Tom Anderson

Is there any such thing as a MAC based ping? Ping is an ICMP protocol
and surely requires an IP address? Hence the "Duh!", as that part of my
response didn't apply to the question the OP asked, get the IP from the
MAC.

There is no purely link-layer ping, but i was thinking about trickery.
I don't think you could use the target's MAC address, a broadcast should
got to each machine. I have never looked at a broadcast packet to see
what MAC address is used in the Ethernet frame (not even sure how to),
maybe the MAC for the default route?

If you're making a real broadcast, it uses the ethernet broadcast address
(FF:FF:FF:FF:FF:FF).

My idea was to send a very special packet, which had the IP broadcast
address in the IP destination address field, but the target machine's MAC
address in the ethernet address field. You'd have to use a super-special
raw socket, a SOCK_PACKET, or direct access to the ethernet driver to do
this. But once you had, ethernet would deliver the packet to the target
machine, and only that machine, and then its IP layer would, hopefully,
interpret it as a packet it should process. It might notice that the MAC
and IP addresses didn't match, and discard it as suspicious, i don't know.

I was then worrying about how you'd get a response from the target that
would put its addresses into your ARP cache (involving a second bit of
trickery at the ARP level), but ...
I've just tried a broadcast ping. I didn't receive any replies, but the
ARP table was populated by every pingable host.

.... in that case, a simple ping should do it. And, indeed, a broadcast
ping would be a crude but effective alternative - as long as you're on the
same ethernet segment (or 'broadcast domain' in a switched ethernet) as
the target.

tom
 
R

Roedy Green

is there any way or posable to get a ip-Address from mac address, i
mean that i have the mac address of a machine and i want to known the
ip address of that mac id or machine.....

try this:

use NetworkInterface.getByName to get a NetWorkInterface object.

Check you have the correct MAC with getHardwareAddress.

use getInetAddresses to get a list of associated IPs.

If that does not work, horse around with java.net.NetworkInterface
methods.
 
T

Tom Anderson

try this:

use NetworkInterface.getByName to get a NetWorkInterface object.

Check you have the correct MAC with getHardwareAddress.

use getInetAddresses to get a list of associated IPs.

If that does not work, horse around with java.net.NetworkInterface
methods.

I think the OP was asking about doing MAC -> IP for a *remote* machine.
NetworkInterface will only help you for interfaces on the local host.

tom
 
R

Roedy Green

I think the OP was asking about doing MAC -> IP for a *remote* machine.

IIRC the MACs of remote machines are considered secret. He then knows
the MAC through some mysterious means. I would not hold out hope of
any ability to manipulate MAC to IP without running some code on the
remote machine.
 
M

Mark Space

BigZero said:
well i m getting mac address from SNMP, i known that i can get ip
address if i query the ip OID.
but the ip address changes(DHCP) so we want to keep the history of a
machine so i m using mac address that never changes, so here all want

In this sort of scenario, it's usual to give the machine a name that
doesn't change (for example, machine1.example.com) and then use that to
look up the machine. That way if IP address changes, the name doesn't.

If you have some IT genius who's invented some sort of random, changing
name policy, they you're hosed.

On unix, you can use nslookup to find server names from IP addresses.

I don't see an nslookup for Java, but Google yields some hits when
searching, so you might find some free Java code that does what you need.
 
T

Tom Anderson

IIRC the MACs of remote machines are considered secret.

Given that they're written on every network packet the machines send out,
and knowledge of them is required in order to send packets back to those
machines, that seems a pretty radical kind of secrecy.

Certainly, MAC (or other link-layer) addresses are thoroughly encapsulated
by the network stack on the local machine, so user-level programs don't
need to worry about them, but i wouldn't call that keeping them secret.
You can find out about them using the arp -a command on unix; i assume
there's something similar on windows.
He then knows the MAC through some mysterious means.

Yes, perhaps he's mastered the dark secrets of the 'ifconfig' command.
I would not hold out hope of any ability to manipulate MAC to IP without
running some code on the remote machine.

Well, if by 'manipulate' you mean changing the mapping, then no - either
on the remote machine, or on the DHCP machine which gives it its IP
address. But if you mean find out what the mapping is, then that's
eminently possible.

tom
 
T

Tom Anderson

In this sort of scenario, it's usual to give the machine a name that
doesn't change (for example, machine1.example.com) and then use that to
look up the machine. That way if IP address changes, the name doesn't.

If you have some IT genius who's invented some sort of random, changing
name policy, they you're hosed.

Where i work, machines are allocated IP numbers and addresses by DHCP,
with the hostnames being constructed from the address. Right now, my work
machine is 128.40.81.98 and mrclmcb98.mcbl.ucl.ac.uk. Tomorrow, both could
be different. I believe many networks are run this way.

It would be vastly better if the hostnames were constant. This could be
done by having a static mapping at the DHCP server, but that would be a
bit of a pain to administer. It could also be done by transmitting a
desired machine name as a client-identifer option in the DHCP request
(which is supported by MacOS, and i would guess also by windows):

http://tools.ietf.org/html/rfc2132#section-9.14

And having the DHCP server use that to form the address.

The fact that all this doesn't work is the reason why Apple came up with
zeroconf:

http://www.zeroconf.org/

Which does this, amongst other things - participating machines run a
micro-DNS server, through which they expose their own locally-chosen
hostname, plus other things like shared volumes, printers, etc.
I don't see an nslookup for Java, but Google yields some hits when
searching, so you might find some free Java code that does what you
need.

Here's one:

http://www.dnsjava.org/index.html

tom
 
R

Roedy Green

Yes, perhaps he's mastered the dark secrets of the 'ifconfig' command.

That is how you find out your OWN MAC. The way he found out the remote
MAC required some unspecified fiddle to get the machine to reveal it
to the outside world, perhaps via a human on the telephone.

The MAC is confidential in the sense the Java Applet sandbox will IIRC
not let you find out the MAC of your own machine and tattle to another
machine, unless you sign the applet.

It is not a secret in the sense of a certificate private key.
 

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,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top